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

Side by Side Diff: chrome/browser/policy/app_pack_updater.cc

Issue 10692168: Moved ExternalExtensionLoaders/Providers into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Even later master Created 8 years, 5 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 | « chrome/browser/policy/app_pack_updater.h ('k') | chrome/chrome_browser_extensions.gypi » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy/app_pack_updater.h" 5 #include "chrome/browser/policy/app_pack_updater.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/cros_settings.h" 16 #include "chrome/browser/chromeos/cros_settings.h"
17 #include "chrome/browser/chromeos/cros_settings_names.h" 17 #include "chrome/browser/chromeos/cros_settings_names.h"
18 #include "chrome/browser/extensions/crx_installer.h" 18 #include "chrome/browser/extensions/crx_installer.h"
19 #include "chrome/browser/extensions/external_extension_loader.h" 19 #include "chrome/browser/extensions/external_loader.h"
20 #include "chrome/browser/extensions/external_extension_provider_impl.h" 20 #include "chrome/browser/extensions/external_provider_impl.h"
21 #include "chrome/browser/extensions/updater/extension_downloader.h" 21 #include "chrome/browser/extensions/updater/extension_downloader.h"
22 #include "chrome/browser/policy/browser_policy_connector.h" 22 #include "chrome/browser/policy/browser_policy_connector.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_details.h" 26 #include "content/public/browser/notification_details.h"
27 #include "content/public/browser/notification_service.h" 27 #include "content/public/browser/notification_service.h"
28 #include "content/public/browser/notification_source.h" 28 #include "content/public/browser/notification_source.h"
29 29
30 using content::BrowserThread; 30 using content::BrowserThread;
31 using file_util::FileEnumerator; 31 using file_util::FileEnumerator;
32 32
33 namespace policy { 33 namespace policy {
34 34
35 namespace { 35 namespace {
36 36
37 // Directory where the AppPack extensions are cached. 37 // Directory where the AppPack extensions are cached.
38 const char kAppPackCacheDir[] = "/var/cache/app_pack"; 38 const char kAppPackCacheDir[] = "/var/cache/app_pack";
39 39
40 // File name extension for CRX files (not case sensitive). 40 // File name extension for CRX files (not case sensitive).
41 const char kCRXFileExtension[] = ".crx"; 41 const char kCRXFileExtension[] = ".crx";
42 42
43 } // namespace 43 } // namespace
44 44
45 const char AppPackUpdater::kExtensionId[] = "extension-id"; 45 const char AppPackUpdater::kExtensionId[] = "extension-id";
46 const char AppPackUpdater::kUpdateUrl[] = "update-url"; 46 const char AppPackUpdater::kUpdateUrl[] = "update-url";
47 47
48 // A custom ExternalExtensionLoader that the AppPackUpdater creates and uses to 48 // A custom extensions::ExternalLoader that the AppPackUpdater creates and uses
49 // publish AppPack updates to the extensions system. 49 // to publish AppPack updates to the extensions system.
50 class AppPackExternalExtensionLoader 50 class AppPackExternalLoader
51 : public ExternalExtensionLoader, 51 : public extensions::ExternalLoader,
52 public base::SupportsWeakPtr<AppPackExternalExtensionLoader> { 52 public base::SupportsWeakPtr<AppPackExternalLoader> {
53 public: 53 public:
54 AppPackExternalExtensionLoader() {} 54 AppPackExternalLoader() {}
55 55
56 // Used by the AppPackUpdater to update the current list of extensions. 56 // Used by the AppPackUpdater to update the current list of extensions.
57 // The format of |prefs| is detailed in the ExternalExtensionLoader/Provider 57 // The format of |prefs| is detailed in the extensions::ExternalLoader/
58 // headers. 58 // Provider headers.
59 void SetCurrentAppPackExtensions(scoped_ptr<base::DictionaryValue> prefs) { 59 void SetCurrentAppPackExtensions(scoped_ptr<base::DictionaryValue> prefs) {
60 app_pack_prefs_.Swap(prefs.get()); 60 app_pack_prefs_.Swap(prefs.get());
61 StartLoading(); 61 StartLoading();
62 } 62 }
63 63
64 // Implementation of ExternalExtensionLoader: 64 // Implementation of extensions::ExternalLoader:
65 virtual void StartLoading() OVERRIDE { 65 virtual void StartLoading() OVERRIDE {
66 prefs_.reset(app_pack_prefs_.DeepCopy()); 66 prefs_.reset(app_pack_prefs_.DeepCopy());
67 VLOG(1) << "AppPack extension loader publishing " 67 VLOG(1) << "AppPack extension loader publishing "
68 << app_pack_prefs_.size() << " crx files."; 68 << app_pack_prefs_.size() << " crx files.";
69 LoadFinished(); 69 LoadFinished();
70 } 70 }
71 71
72 protected: 72 protected:
73 virtual ~AppPackExternalExtensionLoader() {} 73 virtual ~AppPackExternalLoader() {}
74 74
75 private: 75 private:
76 base::DictionaryValue app_pack_prefs_; 76 base::DictionaryValue app_pack_prefs_;
77 77
78 DISALLOW_COPY_AND_ASSIGN(AppPackExternalExtensionLoader); 78 DISALLOW_COPY_AND_ASSIGN(AppPackExternalLoader);
79 }; 79 };
80 80
81 AppPackUpdater::AppPackUpdater(net::URLRequestContextGetter* request_context, 81 AppPackUpdater::AppPackUpdater(net::URLRequestContextGetter* request_context,
82 BrowserPolicyConnector* connector) 82 BrowserPolicyConnector* connector)
83 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 83 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
84 created_extension_loader_(false), 84 created_extension_loader_(false),
85 request_context_(request_context) { 85 request_context_(request_context) {
86 if (connector->GetDeviceMode() == DEVICE_MODE_KIOSK) { 86 if (connector->GetDeviceMode() == DEVICE_MODE_KIOSK) {
87 // Already in Kiosk mode, start loading. 87 // Already in Kiosk mode, start loading.
88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 88 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
89 base::Bind(&AppPackUpdater::Init, 89 base::Bind(&AppPackUpdater::Init,
90 weak_ptr_factory_.GetWeakPtr())); 90 weak_ptr_factory_.GetWeakPtr()));
91 } else if ((connector->GetDeviceMode() == DEVICE_MODE_NOT_SET || 91 } else if ((connector->GetDeviceMode() == DEVICE_MODE_NOT_SET ||
92 connector->GetDeviceMode() == DEVICE_MODE_PENDING) && 92 connector->GetDeviceMode() == DEVICE_MODE_PENDING) &&
93 connector->device_cloud_policy_subsystem()) { 93 connector->device_cloud_policy_subsystem()) {
94 // Not enrolled yet, listen for enrollment. 94 // Not enrolled yet, listen for enrollment.
95 policy_registrar_.reset(new CloudPolicySubsystem::ObserverRegistrar( 95 policy_registrar_.reset(new CloudPolicySubsystem::ObserverRegistrar(
96 connector->device_cloud_policy_subsystem(), this)); 96 connector->device_cloud_policy_subsystem(), this));
97 } else { 97 } else {
98 // Linger as a stub. 98 // Linger as a stub.
99 } 99 }
100 } 100 }
101 101
102 AppPackUpdater::~AppPackUpdater() { 102 AppPackUpdater::~AppPackUpdater() {
103 chromeos::CrosSettings::Get()->RemoveSettingsObserver( 103 chromeos::CrosSettings::Get()->RemoveSettingsObserver(
104 chromeos::kAppPack, this); 104 chromeos::kAppPack, this);
105 net::NetworkChangeNotifier::RemoveIPAddressObserver(this); 105 net::NetworkChangeNotifier::RemoveIPAddressObserver(this);
106 } 106 }
107 107
108 ExternalExtensionLoader* AppPackUpdater::CreateExternalExtensionLoader() { 108 extensions::ExternalLoader* AppPackUpdater::CreateExternalLoader() {
109 if (created_extension_loader_) { 109 if (created_extension_loader_) {
110 NOTREACHED(); 110 NOTREACHED();
111 return NULL; 111 return NULL;
112 } 112 }
113 created_extension_loader_ = true; 113 created_extension_loader_ = true;
114 AppPackExternalExtensionLoader* loader = new AppPackExternalExtensionLoader(); 114 AppPackExternalLoader* loader = new AppPackExternalLoader();
115 extension_loader_ = loader->AsWeakPtr(); 115 extension_loader_ = loader->AsWeakPtr();
116 116
117 // The cache may have been already checked. In that case, load the current 117 // The cache may have been already checked. In that case, load the current
118 // extensions into the loader immediately. 118 // extensions into the loader immediately.
119 UpdateExtensionLoader(); 119 UpdateExtensionLoader();
120 120
121 return loader; 121 return loader;
122 } 122 }
123 123
124 void AppPackUpdater::SetScreenSaverUpdateCallback( 124 void AppPackUpdater::SetScreenSaverUpdateCallback(
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 DownloadMissingExtensions(); 374 DownloadMissingExtensions();
375 } 375 }
376 376
377 void AppPackUpdater::UpdateExtensionLoader() { 377 void AppPackUpdater::UpdateExtensionLoader() {
378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
379 if (!extension_loader_) { 379 if (!extension_loader_) {
380 VLOG(1) << "No AppPack loader created yet, not pushing extensions."; 380 VLOG(1) << "No AppPack loader created yet, not pushing extensions.";
381 return; 381 return;
382 } 382 }
383 383
384 // Build a DictionaryValue with the format that ExternalExtensionProviderImpl 384 // Build a DictionaryValue with the format that
385 // expects, containing info about the locally cached extensions. 385 // extensions::ExternalProviderImpl expects, containing info about the locally
386 // cached extensions.
386 387
387 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue()); 388 scoped_ptr<base::DictionaryValue> prefs(new base::DictionaryValue());
388 for (CacheEntryMap::iterator it = cached_extensions_.begin(); 389 for (CacheEntryMap::iterator it = cached_extensions_.begin();
389 it != cached_extensions_.end(); ++it) { 390 it != cached_extensions_.end(); ++it) {
390 // The screensaver isn't installed into the Profile. 391 // The screensaver isn't installed into the Profile.
391 if (it->first == screen_saver_id_) 392 if (it->first == screen_saver_id_)
392 continue; 393 continue;
393 394
394 base::DictionaryValue* dict = new base::DictionaryValue(); 395 base::DictionaryValue* dict = new base::DictionaryValue();
395 dict->SetString(ExternalExtensionProviderImpl::kExternalCrx, 396 dict->SetString(extensions::ExternalProviderImpl::kExternalCrx,
396 it->second.path); 397 it->second.path);
397 dict->SetString(ExternalExtensionProviderImpl::kExternalVersion, 398 dict->SetString(extensions::ExternalProviderImpl::kExternalVersion,
398 it->second.cached_version); 399 it->second.cached_version);
399 prefs->Set(it->first, dict); 400 prefs->Set(it->first, dict);
400 401
401 VLOG(1) << "Updating AppPack extension loader, added " << it->second.path; 402 VLOG(1) << "Updating AppPack extension loader, added " << it->second.path;
402 } 403 }
403 404
404 extension_loader_->SetCurrentAppPackExtensions(prefs.Pass()); 405 extension_loader_->SetCurrentAppPackExtensions(prefs.Pass());
405 } 406 }
406 407
407 void AppPackUpdater::DownloadMissingExtensions() { 408 void AppPackUpdater::DownloadMissingExtensions() {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 } 586 }
586 } 587 }
587 588
588 void AppPackUpdater::SetUpdateChecked(const std::string& id) { 589 void AppPackUpdater::SetUpdateChecked(const std::string& id) {
589 PolicyEntryMap::iterator entry = app_pack_extensions_.find(id); 590 PolicyEntryMap::iterator entry = app_pack_extensions_.find(id);
590 if (entry != app_pack_extensions_.end()) 591 if (entry != app_pack_extensions_.end())
591 entry->second.update_checked = true; 592 entry->second.update_checked = true;
592 } 593 }
593 594
594 } // namespace policy 595 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/app_pack_updater.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698