OLD | NEW |
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/component_updater/component_updater_service.h" | 5 #include "chrome/browser/component_updater/component_updater_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/at_exit.h" | 10 #include "base/at_exit.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
18 #include "base/stringprintf.h" | 18 #include "base/stringprintf.h" |
19 #include "base/timer.h" | 19 #include "base/timer.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/component_updater/component_unpacker.h" | 21 #include "chrome/browser/component_updater/component_unpacker.h" |
22 #include "chrome/common/chrome_notification_types.h" | 22 #include "chrome/common/chrome_notification_types.h" |
23 #include "chrome/common/chrome_utility_messages.h" | 23 #include "chrome/common/chrome_utility_messages.h" |
24 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
25 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
26 #include "content/browser/utility_process_host.h" | 26 #include "content/browser/utility_process_host.h" |
27 #include "content/common/net/url_fetcher.h" | 27 #include "content/common/net/url_fetcher.h" |
28 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
| 29 #include "content/public/common/url_fetcher_delegate.h" |
29 #include "googleurl/src/gurl.h" | 30 #include "googleurl/src/gurl.h" |
30 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
31 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
32 | 33 |
33 namespace { | 34 namespace { |
34 // Extends an omaha compatible update check url |query| string. Does | 35 // Extends an omaha compatible update check url |query| string. Does |
35 // not mutate the string if it would be longer than |limit| chars. | 36 // not mutate the string if it would be longer than |limit| chars. |
36 bool AddQueryString(std::string id, std::string version, | 37 bool AddQueryString(std::string id, std::string version, |
37 size_t limit, std::string* query) { | 38 size_t limit, std::string* query) { |
38 std::string additional = | 39 std::string additional = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 Version proposed_ver(proposed); | 90 Version proposed_ver(proposed); |
90 if (!proposed_ver.IsValid()) | 91 if (!proposed_ver.IsValid()) |
91 return false; | 92 return false; |
92 return (current.CompareTo(proposed_ver) < 0); | 93 return (current.CompareTo(proposed_ver) < 0); |
93 } | 94 } |
94 | 95 |
95 // Helper template class that allows our main class to have separate | 96 // Helper template class that allows our main class to have separate |
96 // OnURLFetchComplete() callbacks for diffent types of url requests | 97 // OnURLFetchComplete() callbacks for diffent types of url requests |
97 // they are differentiated by the |Ctx| type. | 98 // they are differentiated by the |Ctx| type. |
98 template <typename Del, typename Ctx> | 99 template <typename Del, typename Ctx> |
99 class DelegateWithContext : public URLFetcher::Delegate { | 100 class DelegateWithContext : public content::URLFetcherDelegate { |
100 public: | 101 public: |
101 DelegateWithContext(Del* delegate, Ctx* context) | 102 DelegateWithContext(Del* delegate, Ctx* context) |
102 : delegate_(delegate), context_(context) {} | 103 : delegate_(delegate), context_(context) {} |
103 | 104 |
104 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE { | 105 virtual void OnURLFetchComplete(const URLFetcher* source) OVERRIDE { |
105 delegate_->OnURLFetchComplete(source, context_); | 106 delegate_->OnURLFetchComplete(source, context_); |
106 delete this; | 107 delete this; |
107 } | 108 } |
108 | 109 |
109 private: | 110 private: |
110 ~DelegateWithContext() {} | 111 ~DelegateWithContext() {} |
111 | 112 |
112 Del* delegate_; | 113 Del* delegate_; |
113 Ctx* context_; | 114 Ctx* context_; |
114 }; | 115 }; |
115 // This function creates the right DelegateWithContext using template inference. | 116 // This function creates the right DelegateWithContext using template inference. |
116 template <typename Del, typename Ctx> | 117 template <typename Del, typename Ctx> |
117 URLFetcher::Delegate* MakeContextDelegate(Del* delegate, Ctx* context) { | 118 content::URLFetcherDelegate* MakeContextDelegate(Del* delegate, Ctx* context) { |
118 return new DelegateWithContext<Del, Ctx>(delegate, context); | 119 return new DelegateWithContext<Del, Ctx>(delegate, context); |
119 } | 120 } |
120 | 121 |
121 // Helper to start a url request using |fetcher| with the common flags. | 122 // Helper to start a url request using |fetcher| with the common flags. |
122 void StartFetch(URLFetcher* fetcher, | 123 void StartFetch(URLFetcher* fetcher, |
123 net::URLRequestContextGetter* context_getter, | 124 net::URLRequestContextGetter* context_getter, |
124 bool save_to_file) { | 125 bool save_to_file) { |
125 fetcher->set_request_context(context_getter); | 126 fetcher->set_request_context(context_getter); |
126 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | | 127 fetcher->set_load_flags(net::LOAD_DO_NOT_SEND_COOKIES | |
127 net::LOAD_DO_NOT_SAVE_COOKIES | | 128 net::LOAD_DO_NOT_SAVE_COOKIES | |
(...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 ScheduleNextRun(false); | 744 ScheduleNextRun(false); |
744 } | 745 } |
745 | 746 |
746 // The component update factory. Using the component updater as a singleton | 747 // The component update factory. Using the component updater as a singleton |
747 // is the job of the browser process. | 748 // is the job of the browser process. |
748 ComponentUpdateService* ComponentUpdateServiceFactory( | 749 ComponentUpdateService* ComponentUpdateServiceFactory( |
749 ComponentUpdateService::Configurator* config) { | 750 ComponentUpdateService::Configurator* config) { |
750 DCHECK(config); | 751 DCHECK(config); |
751 return new CrxUpdateService(config); | 752 return new CrxUpdateService(config); |
752 } | 753 } |
OLD | NEW |