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

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

Issue 4727001: Split the private webstore install API into two parts.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include <list> 7 #include <set>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/scoped_temp_dir.h" 13 #include "base/scoped_temp_dir.h"
14 #include "base/singleton.h" 14 #include "base/singleton.h"
15 #include "base/stl_util-inl.h"
15 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
16 #include "base/task.h" 17 #include "base/task.h"
17 #include "base/thread_restrictions.h" 18 #include "base/thread_restrictions.h"
18 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
19 #include "base/version.h" 20 #include "base/version.h"
20 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/browser_thread.h" 22 #include "chrome/browser/browser_thread.h"
22 #include "chrome/browser/extensions/convert_user_script.h" 23 #include "chrome/browser/extensions/convert_user_script.h"
23 #include "chrome/browser/extensions/extensions_service.h" 24 #include "chrome/browser/extensions/extensions_service.h"
24 #include "chrome/browser/extensions/extension_error_reporter.h" 25 #include "chrome/browser/extensions/extension_error_reporter.h"
(...skipping 13 matching lines...) Expand all
38 namespace { 39 namespace {
39 40
40 // Helper function to delete files. This is used to avoid ugly casts which 41 // Helper function to delete files. This is used to avoid ugly casts which
41 // would be necessary with PostMessage since file_util::Delete is overloaded. 42 // would be necessary with PostMessage since file_util::Delete is overloaded.
42 static void DeleteFileHelper(const FilePath& path, bool recursive) { 43 static void DeleteFileHelper(const FilePath& path, bool recursive) {
43 file_util::Delete(path, recursive); 44 file_util::Delete(path, recursive);
44 } 45 }
45 46
46 struct WhitelistedInstallData { 47 struct WhitelistedInstallData {
47 WhitelistedInstallData() {} 48 WhitelistedInstallData() {}
48 std::list<std::string> ids; 49 std::set<std::string> ids;
49 }; 50 };
50 51
51 } // namespace 52 } // namespace
52 53
53 // static 54 // static
54 void CrxInstaller::SetWhitelistedInstallId(const std::string& id) { 55 void CrxInstaller::SetWhitelistedInstallId(const std::string& id) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 Singleton<WhitelistedInstallData>::get()->ids.push_back(id); 57 Singleton<WhitelistedInstallData>::get()->ids.insert(id);
58 }
59
60 // static
61 bool CrxInstaller::IsIdWhitelisted(const std::string& id) {
62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
63 std::set<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids;
64 return ContainsKey(ids, id);
57 } 65 }
58 66
59 // static 67 // static
60 bool CrxInstaller::ClearWhitelistedInstallId(const std::string& id) { 68 bool CrxInstaller::ClearWhitelistedInstallId(const std::string& id) {
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
62 std::list<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids; 70 std::set<std::string>& ids = Singleton<WhitelistedInstallData>::get()->ids;
63 std::list<std::string>::iterator iter = ids.begin(); 71 if (ContainsKey(ids, id)) {
64 for (; iter != ids.end(); ++iter) { 72 ids.erase(id);
65 if (*iter == id) {
66 break;
67 }
68 }
69
70 if (iter != ids.end()) {
71 ids.erase(iter);
72 return true; 73 return true;
73 } 74 }
74
75 return false; 75 return false;
76 } 76 }
77 77
78 CrxInstaller::CrxInstaller(const FilePath& install_directory, 78 CrxInstaller::CrxInstaller(const FilePath& install_directory,
79 ExtensionsService* frontend, 79 ExtensionsService* frontend,
80 ExtensionInstallUI* client) 80 ExtensionInstallUI* client)
81 : install_directory_(install_directory), 81 : install_directory_(install_directory),
82 install_source_(Extension::INTERNAL), 82 install_source_(Extension::INTERNAL),
83 delete_source_(false), 83 delete_source_(false),
84 allow_privilege_increase_(false), 84 allow_privilege_increase_(false),
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 ReportFailureFromUIThread(l10n_util::GetStringFUTF8( 292 ReportFailureFromUIThread(l10n_util::GetStringFUTF8(
293 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT, 293 IDS_EXTENSION_OVERLAPPING_WEB_EXTENT,
294 UTF8ToUTF16(overlapping_extension->name()))); 294 UTF8ToUTF16(overlapping_extension->name())));
295 return; 295 return;
296 } 296 }
297 297
298 current_version_ = 298 current_version_ =
299 frontend_->extension_prefs()->GetVersionString(extension_->id()); 299 frontend_->extension_prefs()->GetVersionString(extension_->id());
300 300
301 bool whitelisted = ClearWhitelistedInstallId(extension_->id()) && 301 bool whitelisted = ClearWhitelistedInstallId(extension_->id()) &&
302 extension_->plugins().empty(); 302 extension_->plugins().empty() && is_gallery_install_;
303 303
304 if (client_ && 304 if (client_ &&
305 (!allow_silent_install_ || !whitelisted)) { 305 (!allow_silent_install_ || !whitelisted)) {
306 AddRef(); // Balanced in Proceed() and Abort(). 306 AddRef(); // Balanced in Proceed() and Abort().
307 client_->ConfirmInstall(this, extension_.get()); 307 client_->ConfirmInstall(this, extension_.get());
308 } else { 308 } else {
309 BrowserThread::PostTask( 309 BrowserThread::PostTask(
310 BrowserThread::FILE, FROM_HERE, 310 BrowserThread::FILE, FROM_HERE,
311 NewRunnableMethod(this, &CrxInstaller::CompleteInstall)); 311 NewRunnableMethod(this, &CrxInstaller::CompleteInstall));
312 } 312 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 client_->OnInstallSuccess(extension_.get()); 411 client_->OnInstallSuccess(extension_.get());
412 412
413 // Tell the frontend about the installation and hand off ownership of 413 // Tell the frontend about the installation and hand off ownership of
414 // extension_ to it. 414 // extension_ to it.
415 frontend_->OnExtensionInstalled(extension_, allow_privilege_increase_); 415 frontend_->OnExtensionInstalled(extension_, allow_privilege_increase_);
416 extension_ = NULL; 416 extension_ = NULL;
417 417
418 // We're done. We don't post any more tasks to ourselves so we are deleted 418 // We're done. We don't post any more tasks to ourselves so we are deleted
419 // soon. 419 // soon.
420 } 420 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/crx_installer.h ('k') | chrome/browser/extensions/crx_installer_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698