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

Side by Side Diff: components/component_updater/component_updater_service.cc

Issue 2154773002: Implement Just-In-Time Flash updates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First Review Pass Created 4 years, 4 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
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 "components/component_updater/component_updater_service.h" 5 #include "components/component_updater/component_updater_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/callback.h" 15 #include "base/callback.h"
16 #include "base/files/file_path.h" 16 #include "base/files/file_path.h"
17 #include "base/files/file_util.h" 17 #include "base/files/file_util.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
22 #include "base/sequenced_task_runner.h" 22 #include "base/sequenced_task_runner.h"
23 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
24 #include "base/strings/utf_string_conversions.h"
24 #include "base/threading/sequenced_worker_pool.h" 25 #include "base/threading/sequenced_worker_pool.h"
25 #include "base/threading/thread_checker.h" 26 #include "base/threading/thread_checker.h"
26 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/time/time.h" 28 #include "base/time/time.h"
28 #include "base/timer/timer.h" 29 #include "base/timer/timer.h"
29 #include "components/component_updater/component_updater_service_internal.h" 30 #include "components/component_updater/component_updater_service_internal.h"
30 #include "components/component_updater/timer.h" 31 #include "components/component_updater/timer.h"
31 #include "components/update_client/configurator.h" 32 #include "components/update_client/configurator.h"
32 #include "components/update_client/crx_update_item.h" 33 #include "components/update_client/crx_update_item.h"
33 #include "components/update_client/update_client.h" 34 #include "components/update_client/update_client.h"
34 #include "components/update_client/utils.h" 35 #include "components/update_client/utils.h"
35 #include "url/gurl.h" 36 #include "url/gurl.h"
36 37
37 using CrxInstaller = update_client::CrxInstaller; 38 using CrxInstaller = update_client::CrxInstaller;
38 using UpdateClient = update_client::UpdateClient; 39 using UpdateClient = update_client::UpdateClient;
39 40
40 namespace { 41 namespace {
41 42
42 enum UpdateType { 43 enum UpdateType {
43 UPDATE_TYPE_MANUAL = 0, 44 UPDATE_TYPE_MANUAL = 0,
44 UPDATE_TYPE_AUTOMATIC, 45 UPDATE_TYPE_AUTOMATIC,
45 UPDATE_TYPE_COUNT, 46 UPDATE_TYPE_COUNT,
46 }; 47 };
47 48
48 } // namespace 49 } // namespace
49 50
50 namespace component_updater { 51 namespace component_updater {
51 52
53 ComponentInfo::ComponentInfo() {
54 }
55 ComponentInfo::~ComponentInfo() {
56 }
57
52 CrxUpdateService::CrxUpdateService( 58 CrxUpdateService::CrxUpdateService(
53 const scoped_refptr<Configurator>& config, 59 const scoped_refptr<Configurator>& config,
54 const scoped_refptr<UpdateClient>& update_client) 60 const scoped_refptr<UpdateClient>& update_client)
55 : config_(config), 61 : config_(config),
56 update_client_(update_client), 62 update_client_(update_client),
57 blocking_task_runner_(config->GetSequencedTaskRunner()) { 63 blocking_task_runner_(config->GetSequencedTaskRunner()) {
58 AddObserver(this); 64 AddObserver(this);
59 } 65 }
60 66
61 CrxUpdateService::~CrxUpdateService() { 67 CrxUpdateService::~CrxUpdateService() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Update the registration data if the component has been registered before. 121 // Update the registration data if the component has been registered before.
116 const std::string id(GetCrxComponentID(component)); 122 const std::string id(GetCrxComponentID(component));
117 auto it = components_.find(id); 123 auto it = components_.find(id);
118 if (it != components_.end()) { 124 if (it != components_.end()) {
119 it->second = component; 125 it->second = component;
120 return true; 126 return true;
121 } 127 }
122 128
123 components_.insert(std::make_pair(id, component)); 129 components_.insert(std::make_pair(id, component));
124 components_order_.push_back(id); 130 components_order_.push_back(id);
131 for (const auto& mime_type : component.handled_mime_types)
132 component_ids_by_mime_type_[mime_type] = id;
125 133
126 // Create an initial state for this component. The state is mutated in 134 // Create an initial state for this component. The state is mutated in
127 // response to events from the UpdateClient instance. 135 // response to events from the UpdateClient instance.
128 CrxUpdateItem item; 136 CrxUpdateItem item;
129 item.id = id; 137 item.id = id;
130 item.component = component; 138 item.component = component;
131 const auto inserted = component_states_.insert(std::make_pair(id, item)); 139 const auto inserted = component_states_.insert(std::make_pair(id, item));
132 DCHECK(inserted.second); 140 DCHECK(inserted.second);
133 141
134 // Start the timer if this is the first component registered. The first timer 142 // Start the timer if this is the first component registered. The first timer
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 186 }
179 187
180 std::vector<std::string> CrxUpdateService::GetComponentIDs() const { 188 std::vector<std::string> CrxUpdateService::GetComponentIDs() const {
181 DCHECK(thread_checker_.CalledOnValidThread()); 189 DCHECK(thread_checker_.CalledOnValidThread());
182 std::vector<std::string> ids; 190 std::vector<std::string> ids;
183 for (const auto& it : components_) 191 for (const auto& it : components_)
184 ids.push_back(it.first); 192 ids.push_back(it.first);
185 return ids; 193 return ids;
186 } 194 }
187 195
196 bool CrxUpdateService::GetComponentForMimeType(const std::string& mime_type,
197 ComponentInfo* info) const {
198 DCHECK(thread_checker_.CalledOnValidThread());
199 const auto it = component_ids_by_mime_type_.find(mime_type);
200 if (it == component_ids_by_mime_type_.end())
201 return false;
202 const auto component = GetComponent(it->second);
203 if (component == NULL)
Bernhard Bauer 2016/07/28 10:25:10 nullptr :) Or just directly use it in the check.
waffles 2016/07/28 20:06:27 Done.
204 return false;
205 info->id = GetCrxComponentID(*component);
206 base::UTF8ToUTF16(component->name.c_str(), component->name.size(),
Bernhard Bauer 2016/07/28 10:25:10 I would use the version of UTF8ToUTF16 that takes
waffles 2016/07/28 20:06:27 Done.
207 &info->name);
208 return true;
209 }
210
188 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() { 211 OnDemandUpdater& CrxUpdateService::GetOnDemandUpdater() {
189 DCHECK(thread_checker_.CalledOnValidThread()); 212 DCHECK(thread_checker_.CalledOnValidThread());
190 return *this; 213 return *this;
191 } 214 }
192 215
193 const CrxComponent* CrxUpdateService::GetComponent( 216 const CrxComponent* CrxUpdateService::GetComponent(
194 const std::string& id) const { 217 const std::string& id) const {
195 DCHECK(thread_checker_.CalledOnValidThread()); 218 DCHECK(thread_checker_.CalledOnValidThread());
196 const auto it(components_.find(id)); 219 const auto it(components_.find(id));
197 return it != components_.end() ? &(it->second) : NULL; 220 return it != components_.end() ? &(it->second) : NULL;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // TODO(sorin): consider making this a singleton. 414 // TODO(sorin): consider making this a singleton.
392 std::unique_ptr<ComponentUpdateService> ComponentUpdateServiceFactory( 415 std::unique_ptr<ComponentUpdateService> ComponentUpdateServiceFactory(
393 const scoped_refptr<Configurator>& config) { 416 const scoped_refptr<Configurator>& config) {
394 DCHECK(config); 417 DCHECK(config);
395 auto update_client = update_client::UpdateClientFactory(config); 418 auto update_client = update_client::UpdateClientFactory(config);
396 return base::WrapUnique( 419 return base::WrapUnique(
397 new CrxUpdateService(config, std::move(update_client))); 420 new CrxUpdateService(config, std::move(update_client)));
398 } 421 }
399 422
400 } // namespace component_updater 423 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698