2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-09-23 11:14:30 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|
|
|
|
#define ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|
|
|
|
|
2014-09-23 12:30:07 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-09-23 11:14:30 +00:00
|
|
|
#include "atom/common/asar/archive.h"
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/memory/ref_counted.h"
|
|
|
|
#include "base/memory/weak_ptr.h"
|
|
|
|
#include "net/url_request/url_request_job.h"
|
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class TaskRunner;
|
|
|
|
}
|
|
|
|
|
2014-09-23 12:30:07 +00:00
|
|
|
namespace net {
|
|
|
|
class FileStream;
|
|
|
|
}
|
|
|
|
|
2014-09-23 11:14:30 +00:00
|
|
|
namespace asar {
|
|
|
|
|
|
|
|
class URLRequestAsarJob : public net::URLRequestJob {
|
|
|
|
public:
|
|
|
|
URLRequestAsarJob(net::URLRequest* request,
|
|
|
|
net::NetworkDelegate* network_delegate,
|
2014-09-25 12:38:12 +00:00
|
|
|
Archive* archive,
|
2014-09-23 11:14:30 +00:00
|
|
|
const base::FilePath& file_path,
|
|
|
|
const scoped_refptr<base::TaskRunner>& file_task_runner);
|
|
|
|
|
|
|
|
// net::URLRequestJob:
|
|
|
|
virtual void Start() OVERRIDE;
|
|
|
|
virtual void Kill() OVERRIDE;
|
|
|
|
virtual bool ReadRawData(net::IOBuffer* buf,
|
|
|
|
int buf_size,
|
|
|
|
int* bytes_read) OVERRIDE;
|
|
|
|
virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~URLRequestAsarJob();
|
|
|
|
|
|
|
|
private:
|
2014-09-23 12:30:07 +00:00
|
|
|
// Callback after opening file on a background thread.
|
|
|
|
void DidOpen(int result);
|
|
|
|
|
|
|
|
// Callback after seeking to the beginning of |byte_range_| in the file
|
|
|
|
// on a background thread.
|
|
|
|
void DidSeek(int64 result);
|
|
|
|
|
|
|
|
// Callback after data is asynchronously read from the file into |buf|.
|
|
|
|
void DidRead(scoped_refptr<net::IOBuffer> buf, int result);
|
|
|
|
|
2014-09-25 12:38:12 +00:00
|
|
|
Archive* archive_;
|
2014-09-23 12:30:07 +00:00
|
|
|
Archive::FileInfo file_info_;
|
2014-09-23 11:14:30 +00:00
|
|
|
base::FilePath file_path_;
|
2014-09-23 12:30:07 +00:00
|
|
|
|
|
|
|
scoped_ptr<net::FileStream> stream_;
|
|
|
|
int64 remaining_bytes_;
|
2014-09-23 13:48:40 +00:00
|
|
|
|
2014-09-23 11:14:30 +00:00
|
|
|
const scoped_refptr<base::TaskRunner> file_task_runner_;
|
|
|
|
|
|
|
|
base::WeakPtrFactory<URLRequestAsarJob> weak_ptr_factory_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(URLRequestAsarJob);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace asar
|
|
|
|
|
|
|
|
#endif // ATOM_BROWSER_NET_ASAR_URL_REQUEST_ASAR_JOB_H_
|