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

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

Issue 2600153003: Fix memory leak in file service. (Closed)
Patch Set: Created 3 years, 12 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 | « no previous file | services/file/file_system.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 "services/file/file_system.h" 13 #include "services/file/file_system.h"
13 #include "services/file/user_id_map.h" 14 #include "services/file/user_id_map.h"
14 #include "services/service_manager/public/cpp/connection.h" 15 #include "services/service_manager/public/cpp/connection.h"
15 #include "services/service_manager/public/cpp/interface_registry.h" 16 #include "services/service_manager/public/cpp/interface_registry.h"
16 #include "services/service_manager/public/cpp/service_context.h" 17 #include "services/service_manager/public/cpp/service_context.h"
17 18
18 namespace file { 19 namespace file {
19 20
20 class FileService::FileSystemObjects 21 class FileService::FileSystemObjects
21 : public base::SupportsWeakPtr<FileSystemObjects> { 22 : public base::SupportsWeakPtr<FileSystemObjects> {
22 public: 23 public:
23 // Created on the main thread. 24 // Created on the main thread.
24 FileSystemObjects(base::FilePath user_dir) : user_dir_(user_dir) {} 25 FileSystemObjects(base::FilePath user_dir) : user_dir_(user_dir) {}
25 26
26 // Destroyed on the |file_service_runner_|. 27 // Destroyed on the |file_service_runner_|.
27 ~FileSystemObjects() {} 28 ~FileSystemObjects() {}
28 29
29 // Called on the |file_service_runner_|. 30 // Called on the |file_service_runner_|.
30 void OnFileSystemRequest(const service_manager::Identity& remote_identity, 31 void OnFileSystemRequest(const service_manager::Identity& remote_identity,
31 mojom::FileSystemRequest request) { 32 mojom::FileSystemRequest request) {
32 if (!lock_table_) 33 if (!lock_table_)
33 lock_table_ = new filesystem::LockTable; 34 lock_table_ = new filesystem::LockTable;
34 file_system_bindings_.AddBinding(new FileSystem(user_dir_, lock_table_), 35 mojo::MakeStrongBinding(
35 std::move(request)); 36 base::MakeUnique<FileSystem>(user_dir_, lock_table_),
37 std::move(request));
36 } 38 }
37 39
38 private: 40 private:
39 mojo::BindingSet<mojom::FileSystem> file_system_bindings_;
40 scoped_refptr<filesystem::LockTable> lock_table_; 41 scoped_refptr<filesystem::LockTable> lock_table_;
41 base::FilePath user_dir_; 42 base::FilePath user_dir_;
42 43
43 DISALLOW_COPY_AND_ASSIGN(FileSystemObjects); 44 DISALLOW_COPY_AND_ASSIGN(FileSystemObjects);
44 }; 45 };
45 46
46 class FileService::LevelDBServiceObjects 47 class FileService::LevelDBServiceObjects
47 : public base::SupportsWeakPtr<LevelDBServiceObjects> { 48 : public base::SupportsWeakPtr<LevelDBServiceObjects> {
48 public: 49 public:
49 // Created on the main thread. 50 // Created on the main thread.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 leveldb::mojom::LevelDBServiceRequest request) { 117 leveldb::mojom::LevelDBServiceRequest request) {
117 leveldb_service_runner_->PostTask( 118 leveldb_service_runner_->PostTask(
118 FROM_HERE, 119 FROM_HERE,
119 base::Bind( 120 base::Bind(
120 &FileService::LevelDBServiceObjects::OnLevelDBServiceRequest, 121 &FileService::LevelDBServiceObjects::OnLevelDBServiceRequest,
121 leveldb_objects_->AsWeakPtr(), remote_identity, 122 leveldb_objects_->AsWeakPtr(), remote_identity,
122 base::Passed(&request))); 123 base::Passed(&request)));
123 } 124 }
124 125
125 } // namespace user_service 126 } // namespace user_service
OLDNEW
« no previous file with comments | « no previous file | services/file/file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698