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

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

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | 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/extension_creator.h" 5 #include "chrome/browser/extensions/extension_creator.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 base::FilePath absolute_extension_dir = 50 base::FilePath absolute_extension_dir =
51 base::MakeAbsoluteFilePath(extension_dir); 51 base::MakeAbsoluteFilePath(extension_dir);
52 if (absolute_extension_dir.empty()) { 52 if (absolute_extension_dir.empty()) {
53 error_message_ = 53 error_message_ =
54 l10n_util::GetStringUTF8(IDS_EXTENSION_CANT_GET_ABSOLUTE_PATH); 54 l10n_util::GetStringUTF8(IDS_EXTENSION_CANT_GET_ABSOLUTE_PATH);
55 return false; 55 return false;
56 } 56 }
57 57
58 // Validate input |private_key| (if provided). 58 // Validate input |private_key| (if provided).
59 if (!private_key_path.value().empty() && 59 if (!private_key_path.value().empty() &&
60 !file_util::PathExists(private_key_path)) { 60 !base::PathExists(private_key_path)) {
61 error_message_ = 61 error_message_ =
62 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_INVALID_PATH); 62 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_INVALID_PATH);
63 return false; 63 return false;
64 } 64 }
65 65
66 // If an |output_private_key| path is given, make sure it doesn't over-write 66 // If an |output_private_key| path is given, make sure it doesn't over-write
67 // an existing private key. 67 // an existing private key.
68 if (private_key_path.value().empty() && 68 if (private_key_path.value().empty() &&
69 !private_key_output_path.value().empty() && 69 !private_key_output_path.value().empty() &&
70 file_util::PathExists(private_key_output_path)) { 70 base::PathExists(private_key_output_path)) {
71 error_message_ = 71 error_message_ =
72 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_EXISTS); 72 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_EXISTS);
73 return false; 73 return false;
74 } 74 }
75 75
76 // Check whether crx file already exists. Should be last check, as this is 76 // Check whether crx file already exists. Should be last check, as this is
77 // a warning only. 77 // a warning only.
78 if (!(run_flags & kOverwriteCRX) && file_util::PathExists(crx_path)) { 78 if (!(run_flags & kOverwriteCRX) && base::PathExists(crx_path)) {
79 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_CRX_EXISTS); 79 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_CRX_EXISTS);
80 error_type_ = kCRXExists; 80 error_type_ = kCRXExists;
81 81
82 return false; 82 return false;
83 } 83 }
84 84
85 return true; 85 return true;
86 } 86 }
87 87
88 bool ExtensionCreator::ValidateManifest(const base::FilePath& extension_dir, 88 bool ExtensionCreator::ValidateManifest(const base::FilePath& extension_dir,
(...skipping 24 matching lines...) Expand all
113 extension_dir, 113 extension_dir,
114 extension_id, 114 extension_id,
115 Manifest::INTERNAL, 115 Manifest::INTERNAL,
116 create_flags, 116 create_flags,
117 &error_message_)); 117 &error_message_));
118 return !!extension.get(); 118 return !!extension.get();
119 } 119 }
120 120
121 crypto::RSAPrivateKey* ExtensionCreator::ReadInputKey(const base::FilePath& 121 crypto::RSAPrivateKey* ExtensionCreator::ReadInputKey(const base::FilePath&
122 private_key_path) { 122 private_key_path) {
123 if (!file_util::PathExists(private_key_path)) { 123 if (!base::PathExists(private_key_path)) {
124 error_message_ = 124 error_message_ =
125 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_NO_EXISTS); 125 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_NO_EXISTS);
126 return NULL; 126 return NULL;
127 } 127 }
128 128
129 std::string private_key_contents; 129 std::string private_key_contents;
130 if (!file_util::ReadFileToString(private_key_path, 130 if (!file_util::ReadFileToString(private_key_path,
131 &private_key_contents)) { 131 &private_key_contents)) {
132 error_message_ = 132 error_message_ =
133 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_FAILED_TO_READ); 133 l10n_util::GetStringUTF8(IDS_EXTENSION_PRIVATE_KEY_FAILED_TO_READ);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 zip_handle.Close(); 229 zip_handle.Close();
230 230
231 signature_creator->Final(signature); 231 signature_creator->Final(signature);
232 return true; 232 return true;
233 } 233 }
234 234
235 bool ExtensionCreator::WriteCRX(const base::FilePath& zip_path, 235 bool ExtensionCreator::WriteCRX(const base::FilePath& zip_path,
236 crypto::RSAPrivateKey* private_key, 236 crypto::RSAPrivateKey* private_key,
237 const std::vector<uint8>& signature, 237 const std::vector<uint8>& signature,
238 const base::FilePath& crx_path) { 238 const base::FilePath& crx_path) {
239 if (file_util::PathExists(crx_path)) 239 if (base::PathExists(crx_path))
240 base::Delete(crx_path, false); 240 base::Delete(crx_path, false);
241 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb")); 241 ScopedStdioHandle crx_handle(file_util::OpenFile(crx_path, "wb"));
242 if (!crx_handle.get()) { 242 if (!crx_handle.get()) {
243 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION); 243 error_message_ = l10n_util::GetStringUTF8(IDS_EXTENSION_SHARING_VIOLATION);
244 return false; 244 return false;
245 } 245 }
246 246
247 std::vector<uint8> public_key; 247 std::vector<uint8> public_key;
248 CHECK(private_key->ExportPublicKey(&public_key)); 248 CHECK(private_key->ExportPublicKey(&public_key));
249 249
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 SignZip(zip_path, key_pair.get(), &signature) && 320 SignZip(zip_path, key_pair.get(), &signature) &&
321 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) { 321 WriteCRX(zip_path, key_pair.get(), signature, crx_path)) {
322 result = true; 322 result = true;
323 } 323 }
324 324
325 base::Delete(zip_path, false); 325 base::Delete(zip_path, false);
326 return result; 326 return result;
327 } 327 }
328 328
329 } // namespace extensions 329 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.cc ('k') | chrome/browser/extensions/extension_protocols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698