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

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 tests. 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 {
18
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 }
28
29 // Forwards the success callback to the status callback. Ignores arguments,
30 // since unmount request does not provide arguments.
31 void OnRequestUnmountSuccess(
32 const fileapi::AsyncFileUtil::StatusCallback& callback,
33 scoped_ptr<base::DictionaryValue> /* result */,
34 bool /* has_next */) {
35 callback.Run(base::File::FILE_OK);
36 }
37
38 } // namespace
9 39
10 ProvidedFileSystem::ProvidedFileSystem() {} 40 ProvidedFileSystem::ProvidedFileSystem() {}
11 41
12 ProvidedFileSystem::ProvidedFileSystem(const std::string& extension_id, 42 ProvidedFileSystem::ProvidedFileSystem(
13 int file_system_id, 43 extensions::EventRouter* event_router,
14 const std::string& file_system_name, 44 RequestManager* request_manager,
15 const base::FilePath& mount_path) 45 const ProvidedFileSystemInfo& file_system_info)
16 : extension_id_(extension_id), 46 : event_router_(event_router),
17 file_system_id_(file_system_id), 47 request_manager_(request_manager),
18 file_system_name_(file_system_name), 48 file_system_info_(file_system_info) {}
19 mount_path_(mount_path) {}
20 49
21 ProvidedFileSystem::~ProvidedFileSystem() {} 50 ProvidedFileSystem::~ProvidedFileSystem() {}
22 51
52 bool ProvidedFileSystem::RequestUnmount(
53 const fileapi::AsyncFileUtil::StatusCallback& callback) {
54 int request_id = request_manager_->CreateRequest(
55 file_system_info_.extension_id(),
56 file_system_info_.file_system_id(),
57 base::Bind(&OnRequestUnmountSuccess, callback),
58 callback);
59
60 if (!request_id)
61 return false;
62
63 scoped_ptr<base::ListValue> values(
64 CreateRequestValues(file_system_info_.file_system_id(), request_id));
65
66 event_router_->DispatchEventToExtension(
67 file_system_info_.extension_id(),
68 make_scoped_ptr(new extensions::Event(
69 extensions::api::file_system_provider::OnUnmountRequested::kEventName,
70 values.Pass())));
71
72 return true;
73 }
74
75 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const {
76 return file_system_info_;
77 }
78
79 ProvidedFileSystemFactory::ProvidedFileSystemFactory() {}
80
81 ProvidedFileSystemFactory::~ProvidedFileSystemFactory() {}
82
83 ProvidedFileSystemInterface* ProvidedFileSystemFactory::Create(
84 Profile* profile,
hashimoto 2014/04/11 06:01:50 Why doesn't this method take event_router instead
mtomasz 2014/04/11 07:11:56 I tried it, but it would be difficult to test. Pro
hashimoto 2014/04/14 10:43:42 Sorry, I still don't understand why changing this
mtomasz 2014/04/15 02:46:40 Yep, I must have been tired writing that comment :
hashimoto 2014/04/15 07:22:45 Sorry, I still don't understand why changing this
mtomasz 2014/04/15 09:42:12 Per offline talk. I misread your first comment. So
85 RequestManager* request_manager,
86 const ProvidedFileSystemInfo& file_system_info) {
87 DCHECK(profile);
88 DCHECK(request_manager);
89 extensions::EventRouter* event_router =
90 extensions::ExtensionSystem::Get(profile)->event_router();
91 DCHECK(event_router);
92 return new ProvidedFileSystem(
93 event_router, request_manager, file_system_info);
94 }
95
23 } // namespace file_system_provider 96 } // namespace file_system_provider
24 } // namespace chromeos 97 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698