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

Side by Side Diff: chrome/common/extensions/extension_file_util.cc

Issue 9374009: Install platform apps into a separate data directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment 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/common/extensions/extension_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 28 matching lines...) Expand all
39 // Returns false and sets the error if script file can't be loaded, 39 // Returns false and sets the error if script file can't be loaded,
40 // or if it's not UTF-8 encoded. 40 // or if it's not UTF-8 encoded.
41 static bool IsScriptValid(const FilePath& path, const FilePath& relative_path, 41 static bool IsScriptValid(const FilePath& path, const FilePath& relative_path,
42 int message_id, std::string* error); 42 int message_id, std::string* error);
43 43
44 const char kInstallDirectoryName[] = "Extensions"; 44 const char kInstallDirectoryName[] = "Extensions";
45 45
46 FilePath InstallExtension(const FilePath& unpacked_source_dir, 46 FilePath InstallExtension(const FilePath& unpacked_source_dir,
47 const std::string& id, 47 const std::string& id,
48 const std::string& version, 48 const std::string& version,
49 const FilePath& all_extensions_dir) { 49 const FilePath& all_extensions_dir,
50 bool should_delete_source) {
50 FilePath extension_dir = all_extensions_dir.AppendASCII(id); 51 FilePath extension_dir = all_extensions_dir.AppendASCII(id);
51 FilePath version_dir; 52 FilePath version_dir;
52 53
53 // Create the extension directory if it doesn't exist already. 54 // Create the extension directory if it doesn't exist already.
54 if (!file_util::PathExists(extension_dir)) { 55 if (!file_util::PathExists(extension_dir)) {
55 if (!file_util::CreateDirectory(extension_dir)) 56 if (!file_util::CreateDirectory(extension_dir))
56 return FilePath(); 57 return FilePath();
57 } 58 }
58 59
59 FilePath profile_temp_dir = GetUserDataTempDir(); 60 FilePath profile_temp_dir = GetUserDataTempDir();
(...skipping 14 matching lines...) Expand all
74 !extension_temp_dir.CreateUniqueTempDirUnderPath(profile_temp_dir)) { 75 !extension_temp_dir.CreateUniqueTempDirUnderPath(profile_temp_dir)) {
75 LOG(ERROR) << "Creating of temp dir under in the profile failed."; 76 LOG(ERROR) << "Creating of temp dir under in the profile failed.";
76 return FilePath(); 77 return FilePath();
77 } 78 }
78 if (!file_util::CopyDirectory(unpacked_source_dir, 79 if (!file_util::CopyDirectory(unpacked_source_dir,
79 extension_temp_dir.path(), true)) { 80 extension_temp_dir.path(), true)) {
80 LOG(ERROR) << "Moving extension from : " << unpacked_source_dir.value() 81 LOG(ERROR) << "Moving extension from : " << unpacked_source_dir.value()
81 << " to : " << extension_temp_dir.path().value() << " failed."; 82 << " to : " << extension_temp_dir.path().value() << " failed.";
82 return FilePath(); 83 return FilePath();
83 } 84 }
84 file_util::Delete(unpacked_source_dir, true); 85 if (should_delete_source)
86 file_util::Delete(unpacked_source_dir, true);
85 FilePath crx_temp_source = 87 FilePath crx_temp_source =
86 extension_temp_dir.path().Append(unpacked_source_dir.BaseName()); 88 extension_temp_dir.path().Append(unpacked_source_dir.BaseName());
87 89
88 // Try to find a free directory. There can be legitimate conflicts in the case 90 // Try to find a free directory. There can be legitimate conflicts in the case
89 // of overinstallation of the same version. 91 // of overinstallation of the same version.
90 const int kMaxAttempts = 100; 92 const int kMaxAttempts = 100;
91 for (int i = 0; i < kMaxAttempts; ++i) { 93 for (int i = 0; i < kMaxAttempts; ++i) {
92 FilePath candidate = extension_dir.AppendASCII( 94 FilePath candidate = extension_dir.AppendASCII(
93 base::StringPrintf("%s_%u", version.c_str(), i)); 95 base::StringPrintf("%s_%u", version.c_str(), i));
94 if (!file_util::PathExists(candidate)) { 96 if (!file_util::PathExists(candidate)) {
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 return temp_path; 681 return temp_path;
680 682
681 return FilePath(); 683 return FilePath();
682 } 684 }
683 685
684 void DeleteFile(const FilePath& path, bool recursive) { 686 void DeleteFile(const FilePath& path, bool recursive) {
685 file_util::Delete(path, recursive); 687 file_util::Delete(path, recursive);
686 } 688 }
687 689
688 } // namespace extension_file_util 690 } // namespace extension_file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698