OLD | NEW |
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/webstore_installer.h" | 5 #include "chrome/browser/extensions/webstore_installer.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/download/download_prefs.h" | 17 #include "chrome/browser/download/download_prefs.h" |
18 #include "chrome/browser/download/download_util.h" | 18 #include "chrome/browser/download/download_util.h" |
19 #include "chrome/browser/extensions/crx_installer.h" | 19 #include "chrome/browser/extensions/crx_installer.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/tabs/tab_strip_model.h" | 21 #include "chrome/browser/tabs/tab_strip_model.h" |
22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
24 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
28 #include "content/browser/download/download_file.h" | |
29 #include "content/browser/download/download_types.h" | 28 #include "content/browser/download/download_types.h" |
30 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/download_manager.h" | 30 #include "content/public/browser/download_manager.h" |
32 #include "content/public/browser/navigation_controller.h" | 31 #include "content/public/browser/navigation_controller.h" |
33 #include "content/public/browser/navigation_entry.h" | 32 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
35 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
36 #include "googleurl/src/gurl.h" | 35 #include "googleurl/src/gurl.h" |
37 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
38 | 37 |
39 using content::BrowserThread; | 38 using content::BrowserThread; |
40 using content::DownloadFile; | |
41 using content::NavigationController; | 39 using content::NavigationController; |
42 | 40 |
43 namespace { | 41 namespace { |
44 | 42 |
45 const char kInvalidIdError[] = "Invalid id"; | 43 const char kInvalidIdError[] = "Invalid id"; |
46 const char kNoBrowserError[] = "No browser found"; | 44 const char kNoBrowserError[] = "No browser found"; |
47 const char kDownloadDirectoryError[] = "Could not create download directory"; | 45 const char kDownloadDirectoryError[] = "Could not create download directory"; |
48 | 46 |
49 const char kInlineInstallSource[] = "inline"; | 47 const char kInlineInstallSource[] = "inline"; |
50 const char kDefaultInstallSource[] = ""; | 48 const char kDefaultInstallSource[] = ""; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 93 |
96 // This is to help avoid a race condition between when we generate this | 94 // This is to help avoid a race condition between when we generate this |
97 // filename and when the download starts writing to it (think concurrently | 95 // filename and when the download starts writing to it (think concurrently |
98 // running sharded browser tests installing the same test file, for | 96 // running sharded browser tests installing the same test file, for |
99 // instance). | 97 // instance). |
100 std::string random_number = | 98 std::string random_number = |
101 base::Uint64ToString(base::RandGenerator(kuint16max)); | 99 base::Uint64ToString(base::RandGenerator(kuint16max)); |
102 | 100 |
103 FilePath file = directory.AppendASCII(id + "_" + random_number + ".crx"); | 101 FilePath file = directory.AppendASCII(id + "_" + random_number + ".crx"); |
104 | 102 |
105 int uniquifier = DownloadFile::GetUniquePathNumber(file); | 103 int uniquifier = file_util::GetUniquePathNumber(file, FILE_PATH_LITERAL("")); |
106 if (uniquifier > 0) | 104 if (uniquifier > 0) |
107 DownloadFile::AppendNumberToPath(&file, uniquifier); | 105 file = file.InsertBeforeExtensionASCII(StringPrintf(" (%d)", uniquifier)); |
108 | 106 |
109 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 107 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
110 base::Bind(callback, file)); | 108 base::Bind(callback, file)); |
111 } | 109 } |
112 | 110 |
113 } // namespace | 111 } // namespace |
114 | 112 |
115 | 113 |
116 WebstoreInstaller::WebstoreInstaller(Profile* profile, | 114 WebstoreInstaller::WebstoreInstaller(Profile* profile, |
117 Delegate* delegate, | 115 Delegate* delegate, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 224 |
227 Release(); // Balanced in Start(). | 225 Release(); // Balanced in Start(). |
228 } | 226 } |
229 | 227 |
230 void WebstoreInstaller::ReportSuccess() { | 228 void WebstoreInstaller::ReportSuccess() { |
231 if (delegate_) | 229 if (delegate_) |
232 delegate_->OnExtensionInstallSuccess(id_); | 230 delegate_->OnExtensionInstallSuccess(id_); |
233 | 231 |
234 Release(); // Balanced in Start(). | 232 Release(); // Balanced in Start(). |
235 } | 233 } |
OLD | NEW |