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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/provided_file_system.cc

Issue 210803003: [fsp] Decouple file_service_provider::Service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 8 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 2014 The Chromium Authors. All rights reserved. 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 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/chromeos/file_system_provider/provided_file_system.h" 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
6 6
7 #include "base/files/file.h"
8 #include "base/values.h"
9 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/extensions/api/file_system_provider.h"
12 #include "extensions/browser/event_router.h"
13 #include "extensions/browser/extension_system.h"
14
7 namespace chromeos { 15 namespace chromeos {
8 namespace file_system_provider { 16 namespace file_system_provider {
17 namespace {
9 18
10 ProvidedFileSystem::ProvidedFileSystem() {} 19 // Creates values to be passed to request events. These values can be extended
20 // by additional fields.
21 scoped_ptr<base::ListValue> CreateRequestValues(int file_system_id,
22 int request_id) {
23 scoped_ptr<base::ListValue> values(new base::ListValue());
24 values->AppendInteger(file_system_id);
25 values->AppendInteger(request_id);
26 return values.Pass();
27 }
11 28
12 ProvidedFileSystem::ProvidedFileSystem(const std::string& extension_id, 29 // Forwards the success callback to the status callback. Ignores arguments,
13 int file_system_id, 30 // since unmount request does not provide arguments.
14 const std::string& file_system_name, 31 void OnRequestUnmountSuccess(
15 const base::FilePath& mount_path) 32 const fileapi::AsyncFileUtil::StatusCallback& callback,
16 : extension_id_(extension_id), 33 scoped_ptr<base::DictionaryValue> /* result */,
17 file_system_id_(file_system_id), 34 bool /* has_next */) {
18 file_system_name_(file_system_name), 35 callback.Run(base::File::FILE_OK);
19 mount_path_(mount_path) {} 36 }
37
38 } // namespace
39
40 ProvidedFileSystem::ProvidedFileSystem(
41 extensions::EventRouter* event_router,
42 RequestManager* request_manager,
43 const ProvidedFileSystemInfo& file_system_info)
44 : event_router_(event_router),
45 request_manager_(request_manager),
46 file_system_info_(file_system_info) {}
20 47
21 ProvidedFileSystem::~ProvidedFileSystem() {} 48 ProvidedFileSystem::~ProvidedFileSystem() {}
22 49
50 bool ProvidedFileSystem::RequestUnmount(
51 const fileapi::AsyncFileUtil::StatusCallback& callback) {
52 int request_id = request_manager_->CreateRequest(
53 file_system_info_.extension_id(),
54 file_system_info_.file_system_id(),
55 base::Bind(&OnRequestUnmountSuccess, callback),
56 callback);
57
58 if (!request_id)
59 return false;
60
61 scoped_ptr<base::ListValue> values(
62 CreateRequestValues(file_system_info_.file_system_id(), request_id));
63
64 event_router_->DispatchEventToExtension(
65 file_system_info_.extension_id(),
66 make_scoped_ptr(new extensions::Event(
67 extensions::api::file_system_provider::OnUnmountRequested::kEventName,
68 values.Pass())));
69
70 return true;
71 }
72
73 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const {
74 return file_system_info_;
75 }
76
77 ProvidedFileSystemFactory::ProvidedFileSystemFactory() {}
78
79 ProvidedFileSystemInterface* ProvidedFileSystemFactory::Create(
80 Profile* profile,
81 RequestManager* request_manager,
82 const ProvidedFileSystemInfo& file_system_info) {
83 DCHECK(profile);
84 DCHECK(request_manager);
85 extensions::EventRouter* event_router =
86 extensions::ExtensionSystem::Get(profile)->event_router();
87 DCHECK(event_router);
88 return new ProvidedFileSystem(
89 event_router, request_manager, file_system_info);
90 }
91
23 } // namespace file_system_provider 92 } // namespace file_system_provider
24 } // namespace chromeos 93 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698