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

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 zipfile installer 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/path_service.h"
8 #include "chrome/browser/extensions/extension_error_reporter.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/unpacked_installer.h"
11 #include "chrome/common/extensions/chrome_utility_extensions_messages.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/utility_process_host.h"
14
15 using content::BrowserThread;
16 using content::UtilityProcessHost;
17
18 ZipFileInstaller::ZipFileInstaller(ExtensionService* extension_service)
19 : be_noisy_on_failure_(true),
20 extension_service_(extension_service->AsWeakPtr()) {
21 }
22
23 void ZipFileInstaller::LoadFromZipFile(const base::FilePath& path) {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25 zip_path_ = path;
26 BrowserThread::PostTask(
27 BrowserThread::IO,
28 FROM_HERE,
29 base::Bind(&ZipFileInstaller::StartWorkOnIOThread, this));
30 }
31
32 ZipFileInstaller::~ZipFileInstaller() {
33 }
34
35 // static
36 scoped_refptr<ZipFileInstaller> ZipFileInstaller::Create(
37 ExtensionService* extension_service) {
38 DCHECK(extension_service);
39 return scoped_refptr<ZipFileInstaller>(
40 new ZipFileInstaller(extension_service));
41 }
42
43 void ZipFileInstaller::StartWorkOnIOThread() {
44 CHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
45 UtilityProcessHost* host =
46 UtilityProcessHost::Create(this, base::MessageLoopProxy::current().get());
47 base::FilePath temp_dir;
48 PathService::Get(base::DIR_TEMP, &temp_dir);
49 host->SetExposedDir(temp_dir.DirName());
asargent_no_longer_on_chrome 2014/07/31 19:59:23 Instead of giving the host access to the entire te
elijahtaylor1 2014/08/06 00:31:54 Done
50 host->Send(new ChromeUtilityMsg_UnzipToDir(zip_path_, temp_dir));
51 }
52
53 void ZipFileInstaller::ReportSuccessOnUIThread(
54 const base::FilePath& unzipped_path) {
55 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
56 extensions::UnpackedInstaller::Create(extension_service_.get())
57 ->Load(unzipped_path);
58 }
59
60 void ZipFileInstaller::ReportErrorOnUIThread(const std::string& error) {
61 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
62 if (extension_service_.get()) {
63 ExtensionErrorReporter::GetInstance()->ReportLoadError(
64 zip_path_, error, extension_service_->profile(), be_noisy_on_failure_);
65 }
66 }
67
68 void ZipFileInstaller::OnUnzipSucceeded(const base::FilePath& unzipped_path) {
69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
70 BrowserThread::PostTask(
71 BrowserThread::UI,
72 FROM_HERE,
73 base::Bind(
74 &ZipFileInstaller::ReportSuccessOnUIThread, this, unzipped_path));
75 }
76
77 void ZipFileInstaller::OnUnzipFailed(const std::string& error) {
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
79 BrowserThread::PostTask(
80 BrowserThread::UI,
81 FROM_HERE,
82 base::Bind(&ZipFileInstaller::ReportErrorOnUIThread, this, error));
83 }
84
85 bool ZipFileInstaller::OnMessageReceived(const IPC::Message& message) {
86 bool handled = true;
87 IPC_BEGIN_MESSAGE_MAP(ZipFileInstaller, message)
88 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Succeeded,
89 OnUnzipSucceeded)
90 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnzipToDir_Failed, OnUnzipFailed)
91 IPC_MESSAGE_UNHANDLED(handled = false)
92 IPC_END_MESSAGE_MAP()
93 return handled;
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698