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

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

Issue 9374009: Install platform apps into a separate data directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 8 years, 10 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 | Annotate | Revision Log
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/extensions/crx_installer.h" 5 #include "chrome/browser/extensions/crx_installer.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/scoped_temp_dir.h" 16 #include "base/scoped_temp_dir.h"
17 #include "base/stl_util.h" 17 #include "base/stl_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "base/time.h" 20 #include "base/time.h"
21 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
22 #include "base/version.h" 22 #include "base/version.h"
23 #include "chrome/browser/browser_process.h" 23 #include "chrome/browser/browser_process.h"
24 #include "chrome/browser/extensions/convert_user_script.h" 24 #include "chrome/browser/extensions/convert_user_script.h"
25 #include "chrome/browser/extensions/convert_web_app.h" 25 #include "chrome/browser/extensions/convert_web_app.h"
26 #include "chrome/browser/extensions/default_apps_trial.h" 26 #include "chrome/browser/extensions/default_apps_trial.h"
27 #include "chrome/browser/extensions/extension_error_reporter.h" 27 #include "chrome/browser/extensions/extension_error_reporter.h"
28 #include "chrome/browser/extensions/extension_service.h" 28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/browser/extensions/permissions_updater.h" 29 #include "chrome/browser/extensions/permissions_updater.h"
30 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/shell_integration.h" 31 #include "chrome/browser/shell_integration.h"
31 #include "chrome/browser/web_applications/web_app.h" 32 #include "chrome/browser/web_applications/web_app.h"
33 #include "chrome/common/chrome_constants.h"
32 #include "chrome/common/chrome_notification_types.h" 34 #include "chrome/common/chrome_notification_types.h"
33 #include "chrome/common/chrome_paths.h" 35 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/extensions/extension_constants.h" 36 #include "chrome/common/extensions/extension_constants.h"
35 #include "chrome/common/extensions/extension_file_util.h" 37 #include "chrome/common/extensions/extension_file_util.h"
36 #include "content/browser/renderer_host/resource_dispatcher_host.h" 38 #include "content/browser/renderer_host/resource_dispatcher_host.h"
37 #include "content/public/browser/browser_thread.h" 39 #include "content/public/browser/browser_thread.h"
38 #include "content/public/browser/notification_service.h" 40 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/user_metrics.h" 41 #include "content/public/browser/user_metrics.h"
40 #include "grit/chromium_strings.h" 42 #include "grit/chromium_strings.h"
41 #include "grit/generated_resources.h" 43 #include "grit/generated_resources.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 133
132 CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak, 134 CrxInstaller::CrxInstaller(base::WeakPtr<ExtensionService> frontend_weak,
133 ExtensionInstallUI* client) 135 ExtensionInstallUI* client)
134 : install_directory_(frontend_weak->install_directory()), 136 : install_directory_(frontend_weak->install_directory()),
135 install_source_(Extension::INTERNAL), 137 install_source_(Extension::INTERNAL),
136 extensions_enabled_(frontend_weak->extensions_enabled()), 138 extensions_enabled_(frontend_weak->extensions_enabled()),
137 delete_source_(false), 139 delete_source_(false),
138 create_app_shortcut_(false), 140 create_app_shortcut_(false),
139 frontend_weak_(frontend_weak), 141 frontend_weak_(frontend_weak),
140 profile_(frontend_weak->profile()), 142 profile_(frontend_weak->profile()),
143 profile_path_(profile_->GetPath()),
benwells 2012/02/13 02:55:44 Do you need this new field? Can you just call prof
141 client_(client), 144 client_(client),
142 apps_require_extension_mime_type_(false), 145 apps_require_extension_mime_type_(false),
143 allow_silent_install_(false), 146 allow_silent_install_(false),
144 install_cause_(extension_misc::INSTALL_CAUSE_UNSET), 147 install_cause_(extension_misc::INSTALL_CAUSE_UNSET),
145 creation_flags_(Extension::NO_FLAGS) { 148 creation_flags_(Extension::NO_FLAGS) {
146 } 149 }
147 150
148 CrxInstaller::~CrxInstaller() { 151 CrxInstaller::~CrxInstaller() {
149 // Delete the temp directory and crx file as necessary. Note that the 152 // Delete the temp directory and crx file as necessary. Note that the
150 // destructor might be called on any thread, so we post a task to the file 153 // destructor might be called on any thread, so we post a task to the file
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 484 }
482 } 485 }
483 486
484 // See how long extension install paths are. This is important on 487 // See how long extension install paths are. This is important on
485 // windows, because file operations may fail if the path to a file 488 // windows, because file operations may fail if the path to a file
486 // exceeds a small constant. See crbug.com/69693 . 489 // exceeds a small constant. See crbug.com/69693 .
487 UMA_HISTOGRAM_CUSTOM_COUNTS( 490 UMA_HISTOGRAM_CUSTOM_COUNTS(
488 "Extensions.CrxInstallDirPathLength", 491 "Extensions.CrxInstallDirPathLength",
489 install_directory_.value().length(), 0, 500, 100); 492 install_directory_.value().length(), 0, 500, 100);
490 493
494 bool separate_data_dir_required =
jeremy 2012/02/12 09:40:28 Could you add a comment explaining when this case
495 extension_->RequiresSeparateUserDataDirectory();
491 FilePath version_dir = extension_file_util::InstallExtension( 496 FilePath version_dir = extension_file_util::InstallExtension(
492 unpacked_extension_root_, 497 unpacked_extension_root_,
493 extension_->id(), 498 extension_->id(),
494 extension_->VersionString(), 499 extension_->VersionString(),
495 install_directory_); 500 install_directory_,
501 separate_data_dir_required ? extension_file_util::DELETE_SOURCE_NO :
502 extension_file_util::DELETE_SOURCE_YES);
496 if (version_dir.empty()) { 503 if (version_dir.empty()) {
497 ReportFailureFromFileThread( 504 ReportFailureFromFileThread(
498 l10n_util::GetStringUTF16( 505 l10n_util::GetStringUTF16(
499 IDS_EXTENSION_MOVE_DIRECTORY_TO_PROFILE_FAILED)); 506 IDS_EXTENSION_MOVE_DIRECTORY_TO_PROFILE_FAILED));
500 return; 507 return;
501 } 508 }
502 509
510 // If the platform app requires its own data directory then we'll need to
511 // copy the extension into that data directory too.
512 if (separate_data_dir_required) {
benwells 2012/02/13 02:55:44 What about unpacked extensions? Can this move into
513 FilePath data_dir =
514 web_app::GetWebAppDataDirectory(profile_path_, *extension_);
515 FilePath profile_path = data_dir.AppendASCII(chrome::kInitialProfile);
516 FilePath extension_path =
517 profile_path.AppendASCII(ExtensionService::kInstallDirectoryName);
518 extension_file_util::InstallExtension(
jeremy 2012/02/12 09:40:28 What if this call fails?
519 unpacked_extension_root_,
520 extension_->id(),
521 extension_->VersionString(),
522 extension_path,
523 extension_file_util::DELETE_SOURCE_YES);
524 }
525
503 // This is lame, but we must reload the extension because absolute paths 526 // This is lame, but we must reload the extension because absolute paths
504 // inside the content scripts are established inside InitFromValue() and we 527 // inside the content scripts are established inside InitFromValue() and we
505 // just moved the extension. 528 // just moved the extension.
506 // TODO(aa): All paths to resources inside extensions should be created 529 // TODO(aa): All paths to resources inside extensions should be created
507 // lazily and based on the Extension's root path at that moment. 530 // lazily and based on the Extension's root path at that moment.
508 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing 531 // TODO(rdevlin.cronin): Continue removing std::string errors and replacing
509 // with string16 532 // with string16
510 std::string error; 533 std::string error;
511 extension_ = extension_file_util::LoadExtension( 534 extension_ = extension_file_util::LoadExtension(
512 version_dir, 535 version_dir,
benwells 2012/02/13 02:55:44 Should this reload the extension from the new data
513 install_source_, 536 install_source_,
514 extension_->creation_flags() | Extension::REQUIRE_KEY, 537 extension_->creation_flags() | Extension::REQUIRE_KEY,
515 &error); 538 &error);
516 CHECK(error.empty()) << error; 539 CHECK(error.empty()) << error;
517 540
518 ReportSuccessFromFileThread(); 541 ReportSuccessFromFileThread();
519 } 542 }
520 543
521 void CrxInstaller::ReportFailureFromFileThread(const string16& error) { 544 void CrxInstaller::ReportFailureFromFileThread(const string16& error) {
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 545 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // Some users (such as the download shelf) need to know when a 629 // Some users (such as the download shelf) need to know when a
607 // CRXInstaller is done. Listening for the EXTENSION_* events 630 // CRXInstaller is done. Listening for the EXTENSION_* events
608 // is problematic because they don't know anything about the 631 // is problematic because they don't know anything about the
609 // extension before it is unpacked, so they cannot filter based 632 // extension before it is unpacked, so they cannot filter based
610 // on the extension. 633 // on the extension.
611 content::NotificationService::current()->Notify( 634 content::NotificationService::current()->Notify(
612 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 635 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
613 content::Source<CrxInstaller>(this), 636 content::Source<CrxInstaller>(this),
614 content::Details<const Extension>(extension)); 637 content::Details<const Extension>(extension));
615 } 638 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698