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

Side by Side Diff: chrome/browser/extensions/install_tracker.cc

Issue 389613006: Prevent duplicate concurrent installs of the same extension (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed update of webstore_result Created 6 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/extensions/install_tracker.h" 5 #include "chrome/browser/extensions/install_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/install_tracker_factory.h" 9 #include "chrome/browser/extensions/install_tracker_factory.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "extensions/browser/extension_prefs.h" 13 #include "extensions/browser/extension_prefs.h"
14 #include "extensions/browser/extension_registry.h"
14 #include "extensions/browser/pref_names.h" 15 #include "extensions/browser/pref_names.h"
15 16
16 namespace extensions { 17 namespace extensions {
17 18
18 InstallTracker::InstallTracker(Profile* profile, 19 InstallTracker::InstallTracker(Profile* profile,
19 extensions::ExtensionPrefs* prefs) { 20 extensions::ExtensionPrefs* prefs)
21 : extension_registry_observer_(this) {
20 registrar_.Add(this, 22 registrar_.Add(this,
21 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED, 23 chrome::NOTIFICATION_EXTENSION_UPDATE_DISABLED,
22 content::Source<Profile>(profile)); 24 content::Source<Profile>(profile));
23 AppSorting* sorting = prefs->app_sorting();
24 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
25 content::Source<AppSorting>(sorting));
26 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST, 25 registrar_.Add(this, chrome::NOTIFICATION_APP_INSTALLED_TO_APPLIST,
27 content::Source<Profile>(profile)); 26 content::Source<Profile>(profile));
27 extension_registry_observer_.Add(ExtensionRegistry::Get(profile));
28 28
29 pref_change_registrar_.Init(prefs->pref_service()); 29 // Prefs may be null in tests.
30 pref_change_registrar_.Add(pref_names::kExtensions, 30 if (prefs) {
31 base::Bind(&InstallTracker::OnAppsReordered, 31 AppSorting* sorting = prefs->app_sorting();
32 base::Unretained(this))); 32 registrar_.Add(this,
33 chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED,
34 content::Source<AppSorting>(sorting));
35 pref_change_registrar_.Init(prefs->pref_service());
36 pref_change_registrar_.Add(
37 pref_names::kExtensions,
38 base::Bind(&InstallTracker::OnAppsReordered, base::Unretained(this)));
39 }
33 } 40 }
34 41
35 InstallTracker::~InstallTracker() { 42 InstallTracker::~InstallTracker() {
36 } 43 }
37 44
38 // static 45 // static
39 InstallTracker* InstallTracker::Get(content::BrowserContext* context) { 46 InstallTracker* InstallTracker::Get(content::BrowserContext* context) {
40 return InstallTrackerFactory::GetForProfile( 47 return InstallTrackerFactory::GetForProfile(
41 Profile::FromBrowserContext(context)); 48 Profile::FromBrowserContext(context));
42 } 49 }
43 50
44 void InstallTracker::AddObserver(InstallObserver* observer) { 51 void InstallTracker::AddObserver(InstallObserver* observer) {
45 observers_.AddObserver(observer); 52 observers_.AddObserver(observer);
46 } 53 }
47 54
48 void InstallTracker::RemoveObserver(InstallObserver* observer) { 55 void InstallTracker::RemoveObserver(InstallObserver* observer) {
49 observers_.RemoveObserver(observer); 56 observers_.RemoveObserver(observer);
50 } 57 }
51 58
59 const ActiveInstallData* InstallTracker::GetActiveInstall(
60 const std::string& extension_id) const {
61 ActiveInstallsMap::const_iterator install_data =
62 active_installs_.find(extension_id);
63 if (install_data == active_installs_.end())
64 return NULL;
65 else
66 return &(install_data->second);
67 }
68
69 void InstallTracker::AddActiveInstall(const ActiveInstallData& install_data) {
70 DCHECK(!install_data.extension_id.empty());
71 DCHECK(active_installs_.find(install_data.extension_id) ==
72 active_installs_.end());
73 active_installs_.insert(
74 std::make_pair(install_data.extension_id, install_data));
75 }
76
77 void InstallTracker::RemoveActiveInstall(const std::string& extension_id) {
78 active_installs_.erase(extension_id);
79 }
80
52 void InstallTracker::OnBeginExtensionInstall( 81 void InstallTracker::OnBeginExtensionInstall(
53 const InstallObserver::ExtensionInstallParams& params) { 82 const InstallObserver::ExtensionInstallParams& params) {
83 ActiveInstallsMap::iterator install_data =
84 active_installs_.find(params.extension_id);
85 if (install_data == active_installs_.end()) {
86 ActiveInstallData install_data(params.extension_id);
87 install_data.is_ephemeral = params.is_ephemeral;
88 active_installs_.insert(std::make_pair(params.extension_id, install_data));
89 }
90
54 FOR_EACH_OBSERVER(InstallObserver, observers_, 91 FOR_EACH_OBSERVER(InstallObserver, observers_,
55 OnBeginExtensionInstall(params)); 92 OnBeginExtensionInstall(params));
56 } 93 }
57 94
58 void InstallTracker::OnBeginExtensionDownload(const std::string& extension_id) { 95 void InstallTracker::OnBeginExtensionDownload(const std::string& extension_id) {
59 FOR_EACH_OBSERVER( 96 FOR_EACH_OBSERVER(
60 InstallObserver, observers_, OnBeginExtensionDownload(extension_id)); 97 InstallObserver, observers_, OnBeginExtensionDownload(extension_id));
61 } 98 }
62 99
63 void InstallTracker::OnDownloadProgress(const std::string& extension_id, 100 void InstallTracker::OnDownloadProgress(const std::string& extension_id,
64 int percent_downloaded) { 101 int percent_downloaded) {
102 ActiveInstallsMap::iterator install_data =
103 active_installs_.find(extension_id);
104 if (install_data != active_installs_.end()) {
105 install_data->second.percent_downloaded = percent_downloaded;
106 } else {
107 NOTREACHED();
108 }
109
65 FOR_EACH_OBSERVER(InstallObserver, observers_, 110 FOR_EACH_OBSERVER(InstallObserver, observers_,
66 OnDownloadProgress(extension_id, percent_downloaded)); 111 OnDownloadProgress(extension_id, percent_downloaded));
67 } 112 }
68 113
69 void InstallTracker::OnBeginCrxInstall(const std::string& extension_id) { 114 void InstallTracker::OnBeginCrxInstall(const std::string& extension_id) {
70 FOR_EACH_OBSERVER( 115 FOR_EACH_OBSERVER(
71 InstallObserver, observers_, OnBeginCrxInstall(extension_id)); 116 InstallObserver, observers_, OnBeginCrxInstall(extension_id));
72 } 117 }
73 118
74 void InstallTracker::OnFinishCrxInstall(const std::string& extension_id, 119 void InstallTracker::OnFinishCrxInstall(const std::string& extension_id,
75 bool success) { 120 bool success) {
76 FOR_EACH_OBSERVER( 121 FOR_EACH_OBSERVER(
77 InstallObserver, observers_, OnFinishCrxInstall(extension_id, success)); 122 InstallObserver, observers_, OnFinishCrxInstall(extension_id, success));
78 } 123 }
79 124
80 void InstallTracker::OnInstallFailure( 125 void InstallTracker::OnInstallFailure(
81 const std::string& extension_id) { 126 const std::string& extension_id) {
127 RemoveActiveInstall(extension_id);
82 FOR_EACH_OBSERVER(InstallObserver, observers_, 128 FOR_EACH_OBSERVER(InstallObserver, observers_,
83 OnInstallFailure(extension_id)); 129 OnInstallFailure(extension_id));
84 } 130 }
85 131
86 void InstallTracker::Shutdown() { 132 void InstallTracker::Shutdown() {
87 FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown()); 133 FOR_EACH_OBSERVER(InstallObserver, observers_, OnShutdown());
88 } 134 }
89 135
90 void InstallTracker::Observe(int type, 136 void InstallTracker::Observe(int type,
91 const content::NotificationSource& source, 137 const content::NotificationSource& source,
(...skipping 15 matching lines...) Expand all
107 *content::Details<const std::string>(details).ptr()); 153 *content::Details<const std::string>(details).ptr());
108 FOR_EACH_OBSERVER(InstallObserver, observers_, 154 FOR_EACH_OBSERVER(InstallObserver, observers_,
109 OnAppInstalledToAppList(extension_id)); 155 OnAppInstalledToAppList(extension_id));
110 break; 156 break;
111 } 157 }
112 default: 158 default:
113 NOTREACHED(); 159 NOTREACHED();
114 } 160 }
115 } 161 }
116 162
163 void InstallTracker::OnExtensionInstalled(
164 content::BrowserContext* browser_context,
165 const Extension* extension,
166 bool is_update) {
167 RemoveActiveInstall(extension->id());
168 }
169
117 void InstallTracker::OnAppsReordered() { 170 void InstallTracker::OnAppsReordered() {
118 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered()); 171 FOR_EACH_OBSERVER(InstallObserver, observers_, OnAppsReordered());
119 } 172 }
120 173
121 } // namespace extensions 174 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/install_tracker.h ('k') | chrome/browser/extensions/install_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698