Index: extensions/browser/extension_protocols.cc |
diff --git a/extensions/browser/extension_protocols.cc b/extensions/browser/extension_protocols.cc |
index 32b6bc0a05bb36979915abe528f3723b9ebc95a6..9885d6392c80be3d88b86269de76d930e3e9bdb9 100644 |
--- a/extensions/browser/extension_protocols.cc |
+++ b/extensions/browser/extension_protocols.cc |
@@ -33,6 +33,8 @@ |
#include "content/public/browser/resource_request_info.h" |
#include "crypto/secure_hash.h" |
#include "crypto/sha2.h" |
+#include "extensions/browser/content_verifier.h" |
+#include "extensions/browser/content_verify_job.h" |
#include "extensions/browser/extensions_browser_client.h" |
#include "extensions/browser/info_map.h" |
#include "extensions/common/constants.h" |
@@ -165,13 +167,15 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { |
const base::FilePath& relative_path, |
const std::string& content_security_policy, |
bool send_cors_header, |
- bool follow_symlinks_anywhere) |
+ bool follow_symlinks_anywhere, |
+ ContentVerifyJob* verify_job) |
: net::URLRequestFileJob( |
request, |
network_delegate, |
base::FilePath(), |
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( |
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), |
+ verify_job_(verify_job), |
seek_position_(0), |
bytes_read_(0), |
directory_path_(directory_path), |
@@ -184,13 +188,6 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { |
if (follow_symlinks_anywhere) { |
resource_.set_follow_symlinks_anywhere(); |
} |
- const std::string& group = |
- base::FieldTrialList::FindFullName("ExtensionContentHashMeasurement"); |
- if (group == "Yes") { |
- base::ElapsedTimer timer; |
- hash_.reset(crypto::SecureHash::Create(crypto::SecureHash::SHA256)); |
- hashing_time_ = timer.Elapsed(); |
- } |
} |
virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { |
@@ -214,9 +211,25 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { |
DCHECK(posted); |
} |
+ virtual void SetExtraRequestHeaders( |
+ const net::HttpRequestHeaders& headers) OVERRIDE { |
+ // TODO(asargent) - we'll need to add proper support for range headers. |
+ // crbug.com/369895. |
+ std::string range_header; |
+ if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { |
+ if (verify_job_.get()) |
rvargas (doing something else)
2014/05/07 18:29:55
nit: get() is not needed for boolean conditions. (
asargent_no_longer_on_chrome
2014/05/07 20:21:51
Done.
|
+ verify_job_ = NULL; |
+ } |
+ URLRequestFileJob::SetExtraRequestHeaders(headers); |
+ } |
+ |
virtual void OnSeekComplete(int64 result) OVERRIDE { |
DCHECK_EQ(seek_position_, 0); |
seek_position_ = result; |
+ // TODO(asargent) - we'll need to add proper support for range headers. |
+ // crbug.com/369895. |
+ if (result > 0 && verify_job_.get()) |
+ verify_job_ = NULL; |
} |
virtual void OnReadComplete(net::IOBuffer* buffer, int result) OVERRIDE { |
@@ -227,23 +240,17 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { |
-result); |
if (result > 0) { |
bytes_read_ += result; |
- if (hash_.get()) { |
- base::ElapsedTimer timer; |
- hash_->Update(buffer->data(), result); |
- hashing_time_ += timer.Elapsed(); |
+ if (verify_job_.get()) { |
+ verify_job_->BytesRead(result, buffer->data()); |
+ |
+ if (remaining_bytes() == result) |
rvargas (doing something else)
2014/05/07 18:29:55
I think it's a little confusing that this relies o
asargent_no_longer_on_chrome
2014/05/07 20:21:51
Yes, good point. I've updated URLRequestFileJob::D
|
+ verify_job_->DoneReading(); |
} |
} |
} |
private: |
virtual ~URLRequestExtensionJob() { |
- if (hash_.get()) { |
- base::ElapsedTimer timer; |
- std::string hash_bytes(crypto::kSHA256Length, 0); |
- hash_->Finish(string_as_array(&hash_bytes), hash_bytes.size()); |
- hashing_time_ += timer.Elapsed(); |
- UMA_HISTOGRAM_TIMES("ExtensionUrlRequest.HashTimeMs", hashing_time_); |
- } |
UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.TotalKbRead", bytes_read_ / 1024); |
UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.SeekPosition", seek_position_); |
} |
@@ -258,8 +265,7 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { |
URLRequestFileJob::Start(); |
} |
- // A hash of the contents we've read from the file. |
- scoped_ptr<crypto::SecureHash> hash_; |
+ scoped_refptr<ContentVerifyJob> verify_job_; |
// The position we seeked to in the file. |
int64 seek_position_; |
@@ -267,9 +273,6 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { |
// The number of bytes of content we read from the file. |
int bytes_read_; |
- // Used to count the total time it takes to do hashing operations. |
- base::TimeDelta hashing_time_; |
- |
net::HttpResponseInfo response_info_; |
base::FilePath directory_path_; |
extensions::ExtensionResource resource_; |
@@ -499,6 +502,14 @@ ExtensionProtocolHandler::MaybeCreateJob( |
return NULL; |
} |
} |
+ ContentVerifyJob* verify_job = NULL; |
+ ContentVerifier* verifier = extension_info_map_->content_verifier(); |
+ if (verifier) { |
+ verify_job = |
+ verifier->CreateJobFor(extension_id, directory_path, relative_path); |
+ if (verify_job) |
+ verify_job->Start(); |
+ } |
return new URLRequestExtensionJob(request, |
network_delegate, |
@@ -507,7 +518,8 @@ ExtensionProtocolHandler::MaybeCreateJob( |
relative_path, |
content_security_policy, |
send_cors_header, |
- follow_symlinks_anywhere); |
+ follow_symlinks_anywhere, |
+ verify_job); |
} |
} // namespace |