Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1132)

Side by Side Diff: extensions/browser/extension_protocols.cc

Issue 664933004: Standardize usage of virtual/override/final in extensions/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/extension_prefs_factory.h ('k') | extensions/browser/extension_registry.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/extension_protocols.h" 5 #include "extensions/browser/extension_protocols.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 : net::URLRequestSimpleJob(request, network_delegate), 77 : net::URLRequestSimpleJob(request, network_delegate),
78 extension_(extension) { 78 extension_(extension) {
79 const bool send_cors_headers = false; 79 const bool send_cors_headers = false;
80 // Leave cache headers out of generated background page jobs. 80 // Leave cache headers out of generated background page jobs.
81 response_info_.headers = BuildHttpHeaders(content_security_policy, 81 response_info_.headers = BuildHttpHeaders(content_security_policy,
82 send_cors_headers, 82 send_cors_headers,
83 base::Time()); 83 base::Time());
84 } 84 }
85 85
86 // Overridden from URLRequestSimpleJob: 86 // Overridden from URLRequestSimpleJob:
87 virtual int GetData(std::string* mime_type, 87 int GetData(std::string* mime_type,
88 std::string* charset, 88 std::string* charset,
89 std::string* data, 89 std::string* data,
90 const net::CompletionCallback& callback) const override { 90 const net::CompletionCallback& callback) const override {
91 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed. 91 // TODO(vadimt): Remove ScopedProfile below once crbug.com/422489 is fixed.
92 tracked_objects::ScopedProfile tracking_profile( 92 tracked_objects::ScopedProfile tracking_profile(
93 FROM_HERE_WITH_EXPLICIT_FUNCTION( 93 FROM_HERE_WITH_EXPLICIT_FUNCTION(
94 "422489 GeneratedBackgroundPageJob::GetData")); 94 "422489 GeneratedBackgroundPageJob::GetData"));
95 95
96 *mime_type = "text/html"; 96 *mime_type = "text/html";
97 *charset = "utf-8"; 97 *charset = "utf-8";
98 98
99 *data = "<!DOCTYPE html>\n<body>\n"; 99 *data = "<!DOCTYPE html>\n<body>\n";
100 const std::vector<std::string>& background_scripts = 100 const std::vector<std::string>& background_scripts =
101 extensions::BackgroundInfo::GetBackgroundScripts(extension_.get()); 101 extensions::BackgroundInfo::GetBackgroundScripts(extension_.get());
102 for (size_t i = 0; i < background_scripts.size(); ++i) { 102 for (size_t i = 0; i < background_scripts.size(); ++i) {
103 *data += "<script src=\""; 103 *data += "<script src=\"";
104 *data += background_scripts[i]; 104 *data += background_scripts[i];
105 *data += "\"></script>\n"; 105 *data += "\"></script>\n";
106 } 106 }
107 107
108 return net::OK; 108 return net::OK;
109 } 109 }
110 110
111 virtual void GetResponseInfo(net::HttpResponseInfo* info) override { 111 void GetResponseInfo(net::HttpResponseInfo* info) override {
112 *info = response_info_; 112 *info = response_info_;
113 } 113 }
114 114
115 private: 115 private:
116 virtual ~GeneratedBackgroundPageJob() {} 116 ~GeneratedBackgroundPageJob() override {}
117 117
118 scoped_refptr<const Extension> extension_; 118 scoped_refptr<const Extension> extension_;
119 net::HttpResponseInfo response_info_; 119 net::HttpResponseInfo response_info_;
120 }; 120 };
121 121
122 base::Time GetFileLastModifiedTime(const base::FilePath& filename) { 122 base::Time GetFileLastModifiedTime(const base::FilePath& filename) {
123 if (base::PathExists(filename)) { 123 if (base::PathExists(filename)) {
124 base::File::Info info; 124 base::File::Info info;
125 if (base::GetFileInfo(filename, &info)) 125 if (base::GetFileInfo(filename, &info))
126 return info.last_modified; 126 return info.last_modified;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // break when updating on Linux. 191 // break when updating on Linux.
192 resource_(extension_id, directory_path, relative_path), 192 resource_(extension_id, directory_path, relative_path),
193 content_security_policy_(content_security_policy), 193 content_security_policy_(content_security_policy),
194 send_cors_header_(send_cors_header), 194 send_cors_header_(send_cors_header),
195 weak_factory_(this) { 195 weak_factory_(this) {
196 if (follow_symlinks_anywhere) { 196 if (follow_symlinks_anywhere) {
197 resource_.set_follow_symlinks_anywhere(); 197 resource_.set_follow_symlinks_anywhere();
198 } 198 }
199 } 199 }
200 200
201 virtual void GetResponseInfo(net::HttpResponseInfo* info) override { 201 void GetResponseInfo(net::HttpResponseInfo* info) override {
202 *info = response_info_; 202 *info = response_info_;
203 } 203 }
204 204
205 virtual void Start() override { 205 void Start() override {
206 request_timer_.reset(new base::ElapsedTimer()); 206 request_timer_.reset(new base::ElapsedTimer());
207 base::FilePath* read_file_path = new base::FilePath; 207 base::FilePath* read_file_path = new base::FilePath;
208 base::Time* last_modified_time = new base::Time(); 208 base::Time* last_modified_time = new base::Time();
209 bool posted = BrowserThread::PostBlockingPoolTaskAndReply( 209 bool posted = BrowserThread::PostBlockingPoolTaskAndReply(
210 FROM_HERE, 210 FROM_HERE,
211 base::Bind(&ReadResourceFilePathAndLastModifiedTime, 211 base::Bind(&ReadResourceFilePathAndLastModifiedTime,
212 resource_, 212 resource_,
213 directory_path_, 213 directory_path_,
214 base::Unretained(read_file_path), 214 base::Unretained(read_file_path),
215 base::Unretained(last_modified_time)), 215 base::Unretained(last_modified_time)),
216 base::Bind(&URLRequestExtensionJob::OnFilePathAndLastModifiedTimeRead, 216 base::Bind(&URLRequestExtensionJob::OnFilePathAndLastModifiedTimeRead,
217 weak_factory_.GetWeakPtr(), 217 weak_factory_.GetWeakPtr(),
218 base::Owned(read_file_path), 218 base::Owned(read_file_path),
219 base::Owned(last_modified_time))); 219 base::Owned(last_modified_time)));
220 DCHECK(posted); 220 DCHECK(posted);
221 } 221 }
222 222
223 virtual bool IsRedirectResponse(GURL* location, 223 bool IsRedirectResponse(GURL* location, int* http_status_code) override {
224 int* http_status_code) override {
225 return false; 224 return false;
226 } 225 }
227 226
228 virtual void SetExtraRequestHeaders( 227 void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers) override {
229 const net::HttpRequestHeaders& headers) override {
230 // TODO(asargent) - we'll need to add proper support for range headers. 228 // TODO(asargent) - we'll need to add proper support for range headers.
231 // crbug.com/369895. 229 // crbug.com/369895.
232 std::string range_header; 230 std::string range_header;
233 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) { 231 if (headers.GetHeader(net::HttpRequestHeaders::kRange, &range_header)) {
234 if (verify_job_.get()) 232 if (verify_job_.get())
235 verify_job_ = NULL; 233 verify_job_ = NULL;
236 } 234 }
237 URLRequestFileJob::SetExtraRequestHeaders(headers); 235 URLRequestFileJob::SetExtraRequestHeaders(headers);
238 } 236 }
239 237
240 virtual void OnSeekComplete(int64 result) override { 238 void OnSeekComplete(int64 result) override {
241 DCHECK_EQ(seek_position_, 0); 239 DCHECK_EQ(seek_position_, 0);
242 seek_position_ = result; 240 seek_position_ = result;
243 // TODO(asargent) - we'll need to add proper support for range headers. 241 // TODO(asargent) - we'll need to add proper support for range headers.
244 // crbug.com/369895. 242 // crbug.com/369895.
245 if (result > 0 && verify_job_.get()) 243 if (result > 0 && verify_job_.get())
246 verify_job_ = NULL; 244 verify_job_ = NULL;
247 } 245 }
248 246
249 virtual void OnReadComplete(net::IOBuffer* buffer, int result) override { 247 void OnReadComplete(net::IOBuffer* buffer, int result) override {
250 if (result >= 0) 248 if (result >= 0)
251 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.OnReadCompleteResult", result); 249 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.OnReadCompleteResult", result);
252 else 250 else
253 UMA_HISTOGRAM_SPARSE_SLOWLY("ExtensionUrlRequest.OnReadCompleteError", 251 UMA_HISTOGRAM_SPARSE_SLOWLY("ExtensionUrlRequest.OnReadCompleteError",
254 -result); 252 -result);
255 if (result > 0) { 253 if (result > 0) {
256 bytes_read_ += result; 254 bytes_read_ += result;
257 if (verify_job_.get()) { 255 if (verify_job_.get()) {
258 verify_job_->BytesRead(result, buffer->data()); 256 verify_job_->BytesRead(result, buffer->data());
259 if (!remaining_bytes()) 257 if (!remaining_bytes())
260 verify_job_->DoneReading(); 258 verify_job_->DoneReading();
261 } 259 }
262 } 260 }
263 } 261 }
264 262
265 private: 263 private:
266 virtual ~URLRequestExtensionJob() { 264 ~URLRequestExtensionJob() override {
267 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.TotalKbRead", bytes_read_ / 1024); 265 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.TotalKbRead", bytes_read_ / 1024);
268 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.SeekPosition", seek_position_); 266 UMA_HISTOGRAM_COUNTS("ExtensionUrlRequest.SeekPosition", seek_position_);
269 if (request_timer_.get()) 267 if (request_timer_.get())
270 UMA_HISTOGRAM_TIMES("ExtensionUrlRequest.Latency", 268 UMA_HISTOGRAM_TIMES("ExtensionUrlRequest.Latency",
271 request_timer_->Elapsed()); 269 request_timer_->Elapsed());
272 } 270 }
273 271
274 void OnFilePathAndLastModifiedTimeRead(base::FilePath* read_file_path, 272 void OnFilePathAndLastModifiedTimeRead(base::FilePath* read_file_path,
275 base::Time* last_modified_time) { 273 base::Time* last_modified_time) {
276 file_path_ = *read_file_path; 274 file_path_ = *read_file_path;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 return extensions::IconsInfo::GetIcons(extension).ContainsPath(path); 381 return extensions::IconsInfo::GetIcons(extension).ContainsPath(path);
384 } 382 }
385 383
386 class ExtensionProtocolHandler 384 class ExtensionProtocolHandler
387 : public net::URLRequestJobFactory::ProtocolHandler { 385 : public net::URLRequestJobFactory::ProtocolHandler {
388 public: 386 public:
389 ExtensionProtocolHandler(bool is_incognito, 387 ExtensionProtocolHandler(bool is_incognito,
390 extensions::InfoMap* extension_info_map) 388 extensions::InfoMap* extension_info_map)
391 : is_incognito_(is_incognito), extension_info_map_(extension_info_map) {} 389 : is_incognito_(is_incognito), extension_info_map_(extension_info_map) {}
392 390
393 virtual ~ExtensionProtocolHandler() {} 391 ~ExtensionProtocolHandler() override {}
394 392
395 virtual net::URLRequestJob* MaybeCreateJob( 393 net::URLRequestJob* MaybeCreateJob(
396 net::URLRequest* request, 394 net::URLRequest* request,
397 net::NetworkDelegate* network_delegate) const override; 395 net::NetworkDelegate* network_delegate) const override;
398 396
399 private: 397 private:
400 const bool is_incognito_; 398 const bool is_incognito_;
401 extensions::InfoMap* const extension_info_map_; 399 extensions::InfoMap* const extension_info_map_;
402 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); 400 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler);
403 }; 401 };
404 402
405 // Creates URLRequestJobs for extension:// URLs. 403 // Creates URLRequestJobs for extension:// URLs.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 return new net::HttpResponseHeaders(raw_headers); 560 return new net::HttpResponseHeaders(raw_headers);
563 } 561 }
564 562
565 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( 563 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
566 bool is_incognito, 564 bool is_incognito,
567 extensions::InfoMap* extension_info_map) { 565 extensions::InfoMap* extension_info_map) {
568 return new ExtensionProtocolHandler(is_incognito, extension_info_map); 566 return new ExtensionProtocolHandler(is_incognito, extension_info_map);
569 } 567 }
570 568
571 } // namespace extensions 569 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_prefs_factory.h ('k') | extensions/browser/extension_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698