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

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

Issue 406713002: Allow drag-and-drop of zipped extensions on chrome://extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use registryobserver, remove zipfileinstallerclient Created 6 years, 4 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/zipfile_installer.h"
6
7 #include "base/file_util.h"
8 #include "base/path_service.h"
9 #include "chrome/browser/extensions/extension_error_reporter.h"
10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/unpacked_installer.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/utility_process_host.h"
16
17 using content::BrowserThread;
18 using content::UtilityProcessHost;
19
20 namespace {
21
22 const char kExtensionHandlerTempDirError[] =
23 "Could not create temporary directory for zipped extension.";
24
25 } // namespace
26
27 namespace extensions {
28
29 ZipFileInstaller::ZipFileInstaller(ExtensionService* extension_service)
30 : be_noisy_on_failure_(true),
31 extension_service_(extension_service->AsWeakPtr()) {
32 }
33
34 void ZipFileInstaller::LoadFromZipFile(const base::FilePath& path) {
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
36 zip_path_ = path;
37 BrowserThread::PostTask(BrowserThread::FILE,
38 FROM_HERE,
39 base::Bind(&ZipFileInstaller::PrepareTempDir, this));
40 }
41
42 void ZipFileInstaller::PrepareTempDir() {
43 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
44 base::FilePath temp_dir;
45 PathService::Get(base::DIR_TEMP, &temp_dir);
46 base::FilePath new_temp_dir;
47 if (!base::CreateTemporaryDirInDir(
48 temp_dir,
49 zip_path_.RemoveExtension().BaseName().value() +
50 FILE_PATH_LITERAL("_"),
51 &new_temp_dir)) {
52 OnUnzipFailed(std::string(kExtensionHandlerTempDirError));
53 return;
54 }
55 BrowserThread::PostTask(
56 BrowserThread::IO,
57 FROM_HERE,
58 base::Bind(&ZipFileInstaller::StartWorkOnIOThread, this, new_temp_dir));
59 }
60
61 ZipFileInstaller::~ZipFileInstaller() {
62 }
63
64 // static
65 scoped_refptr<ZipFileInstaller> ZipFileInstaller::Create(
66 ExtensionService* extension_service) {
67 DCHECK(extension_service);
68 return scoped_refptr<ZipFileInstaller>(
69 new ZipFileInstaller(extension_service));
70 }
71
72 void ZipFileInstaller::StartWorkOnIOThread(const base::FilePath& temp_dir) {
73 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
74 UtilityProcessHost* host =
75 UtilityProcessHost::Create(this, base::MessageLoopProxy::current().get());
76 host->SetExposedDir(temp_dir);
77 host->Send(new ChromeUtilityMsg_UnzipToDir(zip_path_, temp_dir));
78 }
79
80 void ZipFileInstaller::ReportSuccessOnUIThread(
81 const base::FilePath& unzipped_path) {
82 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
83 UnpackedInstaller::Create(extension_service_.get())->Load(unzipped_path);
asargent_no_longer_on_chrome 2014/08/07 17:28:25 nit: since extension_service_ is a weak ptr, you s
elijahtaylor1 2014/08/07 22:41:25 Done.
84 }
85
86 void ZipFileInstaller::ReportErrorOnUIThread(const std::string& error) {
87 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 if (extension_service_.get()) {
89 ExtensionErrorReporter::GetInstance()->ReportLoadError(
90 zip_path_, error, extension_service_->profile(), be_noisy_on_failure_);
asargent_no_longer_on_chrome 2014/08/07 17:28:24 need same weak ptr check here too
elijahtaylor1 2014/08/07 22:41:25 Weird, I had it for this function actually.
91 }
92 }
93
94 void ZipFileInstaller::OnUnzipSucceeded(const base::FilePath& unzipped_path) {
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
96 BrowserThread::PostTask(
97 BrowserThread::UI,
98 FROM_HERE,
99 base::Bind(
100 &ZipFileInstaller::ReportSuccessOnUIThread, this, unzipped_path));
101 }
102
103 void ZipFileInstaller::OnUnzipFailed(const std::string& error) {
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
105 BrowserThread::PostTask(
106 BrowserThread::UI,
107 FROM_HERE,
108 base::Bind(&ZipFileInstaller::ReportErrorOnUIThread, this, error));
109 }
110
111 bool ZipFileInstaller::OnMessageReceived(const IPC::Message& message) {
112 bool handled = true;
113 IPC_BEGIN_MESSAGE_MAP(ZipFileInstaller, message)
114 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Succeeded,
115 OnUnzipSucceeded)
116 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Failed, OnUnzipFailed)
117 IPC_MESSAGE_UNHANDLED(handled = false)
118 IPC_END_MESSAGE_MAP()
119 return handled;
120 }
121
122 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698