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

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: add test 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/common/extensions/chrome_utility_extensions_messages.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/utility_process_host.h"
15
16 using content::BrowserThread;
17 using content::UtilityProcessHost;
18
19 namespace {
20
21 const char kExtensionHandlerTempDirError[] =
22 "Could not create temporary directory for zipped extension.";
23
24 } // namespace
25
26 namespace extensions {
27
28 ZipFileInstaller::ZipFileInstaller(ExtensionService* extension_service,
29 ZipFileInstallerClient* client)
30 : be_noisy_on_failure_(true),
31 extension_service_(extension_service->AsWeakPtr()),
32 client_(client) {
33 }
34
35 void ZipFileInstaller::LoadFromZipFile(const base::FilePath& path) {
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 zip_path_ = path;
38 BrowserThread::PostTask(BrowserThread::FILE,
39 FROM_HERE,
40 base::Bind(&ZipFileInstaller::PrepareTempDir, this));
41 }
42
43 void ZipFileInstaller::PrepareTempDir() {
44 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
45 base::FilePath temp_dir;
46 PathService::Get(base::DIR_TEMP, &temp_dir);
47 base::FilePath new_temp_dir;
48 if (!base::CreateTemporaryDirInDir(
49 temp_dir,
50 zip_path_.RemoveExtension().BaseName().value() +
51 FILE_PATH_LITERAL("_"),
52 &new_temp_dir)) {
53 OnUnzipFailed(std::string(kExtensionHandlerTempDirError));
54 return;
55 }
56 BrowserThread::PostTask(
57 BrowserThread::IO,
58 FROM_HERE,
59 base::Bind(&ZipFileInstaller::StartWorkOnIOThread, this, new_temp_dir));
60 }
61
62 ZipFileInstaller::~ZipFileInstaller() {
63 }
64
65 // static
66 scoped_refptr<ZipFileInstaller> ZipFileInstaller::Create(
67 ExtensionService* extension_service,
68 ZipFileInstallerClient* client) {
69 DCHECK(extension_service);
70 return scoped_refptr<ZipFileInstaller>(
71 new ZipFileInstaller(extension_service, client));
72 }
73
74 void ZipFileInstaller::StartWorkOnIOThread(const base::FilePath& temp_dir) {
75 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
76 UtilityProcessHost* host =
77 UtilityProcessHost::Create(this, base::MessageLoopProxy::current().get());
78 host->SetExposedDir(temp_dir);
79 host->Send(new ChromeUtilityMsg_UnzipToDir(zip_path_, temp_dir));
80 }
81
82 void ZipFileInstaller::ReportSuccessOnUIThread(
83 const base::FilePath& unzipped_path) {
84 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
85 // UnpackedInstaller::Create(extension_service_.get())->Load(unzipped_path);
asargent_no_longer_on_chrome 2014/08/06 20:39:01 Maybe the fact that this line is commented out is
elijahtaylor1 2014/08/06 20:42:51 Oh you and your astute reading of my crap code...
86 if (client_.get())
87 client_->OnUnzipSuccess(unzipped_path);
88 }
89
90 void ZipFileInstaller::ReportErrorOnUIThread(const std::string& error) {
91 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
92 if (extension_service_.get()) {
93 ExtensionErrorReporter::GetInstance()->ReportLoadError(
94 zip_path_, error, extension_service_->profile(), be_noisy_on_failure_);
95 }
96 if (client_.get())
97 client_->OnUnzipFailure(error);
98 }
99
100 void ZipFileInstaller::OnUnzipSucceeded(const base::FilePath& unzipped_path) {
101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
102 BrowserThread::PostTask(
103 BrowserThread::UI,
104 FROM_HERE,
105 base::Bind(
106 &ZipFileInstaller::ReportSuccessOnUIThread, this, unzipped_path));
107 }
108
109 void ZipFileInstaller::OnUnzipFailed(const std::string& error) {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
111 BrowserThread::PostTask(
112 BrowserThread::UI,
113 FROM_HERE,
114 base::Bind(&ZipFileInstaller::ReportErrorOnUIThread, this, error));
115 }
116
117 bool ZipFileInstaller::OnMessageReceived(const IPC::Message& message) {
118 bool handled = true;
119 IPC_BEGIN_MESSAGE_MAP(ZipFileInstaller, message)
120 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Succeeded,
121 OnUnzipSucceeded)
122 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Failed, OnUnzipFailed)
123 IPC_MESSAGE_UNHANDLED(handled = false)
124 IPC_END_MESSAGE_MAP()
125 return handled;
126 }
127
128 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698