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

Side by Side Diff: services/file/file_service.cc

Issue 2795883002: Eliminate OnConnect usage (Closed)
Patch Set: . Created 3 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
« no previous file with comments | « services/file/file_service.h ('k') | services/identity/identity_service.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/file/file_service.h" 5 #include "services/file/file_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "components/filesystem/lock_table.h" 10 #include "components/filesystem/lock_table.h"
11 #include "components/leveldb/leveldb_service_impl.h" 11 #include "components/leveldb/leveldb_service_impl.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h" 12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 #include "services/file/file_system.h" 13 #include "services/file/file_system.h"
14 #include "services/file/user_id_map.h" 14 #include "services/file/user_id_map.h"
15 #include "services/service_manager/public/cpp/connection.h" 15 #include "services/service_manager/public/cpp/connection.h"
16 #include "services/service_manager/public/cpp/interface_registry.h"
17 #include "services/service_manager/public/cpp/service_context.h" 16 #include "services/service_manager/public/cpp/service_context.h"
18 17
19 namespace file { 18 namespace file {
20 19
21 class FileService::FileSystemObjects 20 class FileService::FileSystemObjects
22 : public base::SupportsWeakPtr<FileSystemObjects> { 21 : public base::SupportsWeakPtr<FileSystemObjects> {
23 public: 22 public:
24 // Created on the main thread. 23 // Created on the main thread.
25 FileSystemObjects(base::FilePath user_dir) : user_dir_(user_dir) {} 24 FileSystemObjects(base::FilePath user_dir) : user_dir_(user_dir) {}
26 25
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 scoped_refptr<base::SingleThreadTaskRunner> file_service_runner, 77 scoped_refptr<base::SingleThreadTaskRunner> file_service_runner,
79 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) { 78 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) {
80 return base::MakeUnique<FileService>(std::move(file_service_runner), 79 return base::MakeUnique<FileService>(std::move(file_service_runner),
81 std::move(leveldb_service_runner)); 80 std::move(leveldb_service_runner));
82 } 81 }
83 82
84 FileService::FileService( 83 FileService::FileService(
85 scoped_refptr<base::SingleThreadTaskRunner> file_service_runner, 84 scoped_refptr<base::SingleThreadTaskRunner> file_service_runner,
86 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner) 85 scoped_refptr<base::SingleThreadTaskRunner> leveldb_service_runner)
87 : file_service_runner_(std::move(file_service_runner)), 86 : file_service_runner_(std::move(file_service_runner)),
88 leveldb_service_runner_(std::move(leveldb_service_runner)) {} 87 leveldb_service_runner_(std::move(leveldb_service_runner)) {
88 registry_.AddInterface<leveldb::mojom::LevelDBService>(this);
89 registry_.AddInterface<mojom::FileSystem>(this);
90 }
89 91
90 FileService::~FileService() { 92 FileService::~FileService() {
91 file_service_runner_->DeleteSoon(FROM_HERE, file_system_objects_.release()); 93 file_service_runner_->DeleteSoon(FROM_HERE, file_system_objects_.release());
92 leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release()); 94 leveldb_service_runner_->DeleteSoon(FROM_HERE, leveldb_objects_.release());
93 } 95 }
94 96
95 void FileService::OnStart() { 97 void FileService::OnStart() {
96 file_system_objects_.reset(new FileService::FileSystemObjects( 98 file_system_objects_.reset(new FileService::FileSystemObjects(
97 GetUserDirForUserId(context()->identity().user_id()))); 99 GetUserDirForUserId(context()->identity().user_id())));
98 leveldb_objects_.reset( 100 leveldb_objects_.reset(
99 new FileService::LevelDBServiceObjects(file_service_runner_)); 101 new FileService::LevelDBServiceObjects(file_service_runner_));
100 } 102 }
101 103
102 bool FileService::OnConnect(const service_manager::ServiceInfo& remote_info, 104 void FileService::OnBindInterface(
103 service_manager::InterfaceRegistry* registry) { 105 const service_manager::ServiceInfo& source_info,
104 registry->AddInterface<leveldb::mojom::LevelDBService>(this); 106 const std::string& interface_name,
105 registry->AddInterface<mojom::FileSystem>(this); 107 mojo::ScopedMessagePipeHandle interface_pipe) {
106 return true; 108 registry_.BindInterface(source_info.identity, interface_name,
109 std::move(interface_pipe));
107 } 110 }
108 111
109 void FileService::Create(const service_manager::Identity& remote_identity, 112 void FileService::Create(const service_manager::Identity& remote_identity,
110 mojom::FileSystemRequest request) { 113 mojom::FileSystemRequest request) {
111 file_service_runner_->PostTask( 114 file_service_runner_->PostTask(
112 FROM_HERE, 115 FROM_HERE,
113 base::Bind(&FileService::FileSystemObjects::OnFileSystemRequest, 116 base::Bind(&FileService::FileSystemObjects::OnFileSystemRequest,
114 file_system_objects_->AsWeakPtr(), remote_identity, 117 file_system_objects_->AsWeakPtr(), remote_identity,
115 base::Passed(&request))); 118 base::Passed(&request)));
116 } 119 }
117 120
118 void FileService::Create(const service_manager::Identity& remote_identity, 121 void FileService::Create(const service_manager::Identity& remote_identity,
119 leveldb::mojom::LevelDBServiceRequest request) { 122 leveldb::mojom::LevelDBServiceRequest request) {
120 leveldb_service_runner_->PostTask( 123 leveldb_service_runner_->PostTask(
121 FROM_HERE, 124 FROM_HERE,
122 base::Bind( 125 base::Bind(
123 &FileService::LevelDBServiceObjects::OnLevelDBServiceRequest, 126 &FileService::LevelDBServiceObjects::OnLevelDBServiceRequest,
124 leveldb_objects_->AsWeakPtr(), remote_identity, 127 leveldb_objects_->AsWeakPtr(), remote_identity,
125 base::Passed(&request))); 128 base::Passed(&request)));
126 } 129 }
127 130
128 } // namespace user_service 131 } // namespace user_service
OLDNEW
« no previous file with comments | « services/file/file_service.h ('k') | services/identity/identity_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698