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

Side by Side Diff: chrome/browser/web_resource/web_resource_service.cc

Issue 8375039: Create a content::UrlFetcher interface that lives in content/public/common and convert users to i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/web_resource/web_resource_service.h" 5 #include "chrome/browser/web_resource/web_resource_service.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 if (web_resource_service_->apply_locale_to_url_) { 64 if (web_resource_service_->apply_locale_to_url_) {
65 std::string locale = g_browser_process->GetApplicationLocale(); 65 std::string locale = g_browser_process->GetApplicationLocale();
66 web_resource_server.append(locale); 66 web_resource_server.append(locale);
67 } 67 }
68 68
69 url_fetcher_.reset(new URLFetcher(GURL( 69 url_fetcher_.reset(new URLFetcher(GURL(
70 web_resource_server), 70 web_resource_server),
71 URLFetcher::GET, this)); 71 URLFetcher::GET, this));
72 // Do not let url fetcher affect existing state in system context (by 72 // Do not let url fetcher affect existing state in system context (by
73 // setting cookies, for example). 73 // setting cookies, for example).
74 url_fetcher_->set_load_flags(net::LOAD_DISABLE_CACHE | 74 url_fetcher_->SetLoadFlags(net::LOAD_DISABLE_CACHE |
75 net::LOAD_DO_NOT_SAVE_COOKIES); 75 net::LOAD_DO_NOT_SAVE_COOKIES);
76 net::URLRequestContextGetter* url_request_context_getter = 76 net::URLRequestContextGetter* url_request_context_getter =
77 g_browser_process->system_request_context(); 77 g_browser_process->system_request_context();
78 url_fetcher_->set_request_context(url_request_context_getter); 78 url_fetcher_->SetRequestContext(url_request_context_getter);
79 url_fetcher_->Start(); 79 url_fetcher_->Start();
80 } 80 }
81 81
82 // From content::URLFetcherDelegate. 82 // From content::URLFetcherDelegate.
83 void OnURLFetchComplete(const URLFetcher* source) { 83 void OnURLFetchComplete(const content::URLFetcher* source) {
84 // Delete the URLFetcher when this function exits. 84 // Delete the URLFetcher when this function exits.
85 scoped_ptr<URLFetcher> clean_up_fetcher(url_fetcher_.release()); 85 scoped_ptr<content::URLFetcher> clean_up_fetcher(url_fetcher_.release());
86 86
87 // Don't parse data if attempt to download was unsuccessful. 87 // Don't parse data if attempt to download was unsuccessful.
88 // Stop loading new web resource data, and silently exit. 88 // Stop loading new web resource data, and silently exit.
89 if (!source->status().is_success() || (source->response_code() != 200)) 89 if (!source->GetStatus().is_success() || (source->GetResponseCode() != 200))
90 return; 90 return;
91 91
92 std::string data; 92 std::string data;
93 source->GetResponseAsString(&data); 93 source->GetResponseAsString(&data);
94 web_resource_service_->UpdateResourceCache(data); 94 web_resource_service_->UpdateResourceCache(data);
95 web_resource_service_->Release(); 95 web_resource_service_->Release();
96 } 96 }
97 97
98 private: 98 private:
99 // So that we can delay our start so as not to affect start-up time; also, 99 // So that we can delay our start so as not to affect start-up time; also,
100 // so that we can schedule future cache updates. 100 // so that we can schedule future cache updates.
101 ScopedRunnableMethodFactory<WebResourceFetcher> fetcher_factory_; 101 ScopedRunnableMethodFactory<WebResourceFetcher> fetcher_factory_;
102 102
103 // The tool that fetches the url data from the server. 103 // The tool that fetches the url data from the server.
104 scoped_ptr<URLFetcher> url_fetcher_; 104 scoped_ptr<content::URLFetcher> url_fetcher_;
105 105
106 // Our owner and creator. Ref counted. 106 // Our owner and creator. Ref counted.
107 WebResourceService* web_resource_service_; 107 WebResourceService* web_resource_service_;
108 }; 108 };
109 109
110 // This class coordinates a web resource unpack and parse task which is run in 110 // This class coordinates a web resource unpack and parse task which is run in
111 // a separate process. Results are sent back to this class and routed to 111 // a separate process. Results are sent back to this class and routed to
112 // the WebResourceService. 112 // the WebResourceService.
113 class WebResourceService::UnpackerClient : public UtilityProcessHost::Client { 113 class WebResourceService::UnpackerClient : public UtilityProcessHost::Client {
114 public: 114 public:
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 293 }
294 294
295 void WebResourceService::UpdateResourceCache(const std::string& json_data) { 295 void WebResourceService::UpdateResourceCache(const std::string& json_data) {
296 UnpackerClient* client = new UnpackerClient(this, json_data); 296 UnpackerClient* client = new UnpackerClient(this, json_data);
297 client->Start(); 297 client->Start();
298 298
299 // Set cache update time in preferences. 299 // Set cache update time in preferences.
300 prefs_->SetString(last_update_time_pref_name_, 300 prefs_->SetString(last_update_time_pref_name_,
301 base::DoubleToString(base::Time::Now().ToDoubleT())); 301 base::DoubleToString(base::Time::Now().ToDoubleT()));
302 } 302 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_manager_browsertest.cc ('k') | chrome/common/net/gaia/gaia_auth_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698