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

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

Issue 210803003: [fsp] Decouple file_service_provider::Service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. 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/request_manager.h" 5 #include "chrome/browser/chromeos/file_system_provider/request_manager.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 8
9 namespace chromeos { 9 namespace chromeos {
10 namespace file_system_provider { 10 namespace file_system_provider {
11 11
12 RequestManager::RequestManager() : next_id_(1) {} 12 RequestManager::RequestManager() : next_id_(1) {}
13 13
14 RequestManager::~RequestManager() {} 14 RequestManager::~RequestManager() {}
15 15
16 int RequestManager::CreateRequest(const ProvidedFileSystem& file_system, 16 int RequestManager::CreateRequest(const std::string& extension_id,
17 int file_system_id,
17 const SuccessCallback& success_callback, 18 const SuccessCallback& success_callback,
18 const ErrorCallback& error_callback) { 19 const ErrorCallback& error_callback) {
19 // The request id is unique per request manager, so per service, thereof 20 // The request id is unique per request manager, so per service, thereof
20 // per profile. 21 // per profile.
21 int request_id = next_id_++; 22 int request_id = next_id_++;
22 23
23 // If cycled the int, then signal an error. 24 // If cycled the int, then signal an error.
24 if (requests_.find(request_id) != requests_.end()) 25 if (requests_.find(request_id) != requests_.end())
25 return 0; 26 return 0;
26 27
27 Request request; 28 Request request;
28 request.file_system = file_system; 29 request.extension_id = extension_id;
30 request.file_system_id = file_system_id;
29 request.success_callback = success_callback; 31 request.success_callback = success_callback;
30 request.error_callback = error_callback; 32 request.error_callback = error_callback;
31 requests_[request_id] = request; 33 requests_[request_id] = request;
32 34
33 return request_id; 35 return request_id;
34 } 36 }
35 37
36 bool RequestManager::FulfillRequest(const ProvidedFileSystem& file_system, 38 bool RequestManager::FulfillRequest(const std::string& extension_id,
39 int file_system_id,
37 int request_id, 40 int request_id,
38 scoped_ptr<base::DictionaryValue> response, 41 scoped_ptr<base::DictionaryValue> response,
39 bool has_next) { 42 bool has_next) {
40 RequestMap::iterator request_it = requests_.find(request_id); 43 RequestMap::iterator request_it = requests_.find(request_id);
41 44
42 if (request_it == requests_.end()) 45 if (request_it == requests_.end())
43 return false; 46 return false;
44 47
45 // Check if the request belongs to the same provided file system. 48 // Check if the request belongs to the same provided file system.
46 if (request_it->second.file_system.file_system_id() != 49 if (request_it->second.file_system_id != file_system_id ||
47 file_system.file_system_id()) { 50 request_it->second.extension_id != extension_id) {
48 return false; 51 return false;
49 } 52 }
50 53
51 if (!request_it->second.success_callback.is_null()) 54 if (!request_it->second.success_callback.is_null())
52 request_it->second.success_callback.Run(response.Pass(), has_next); 55 request_it->second.success_callback.Run(response.Pass(), has_next);
53 if (!has_next) 56 if (!has_next)
54 requests_.erase(request_it); 57 requests_.erase(request_it);
55 58
56 return true; 59 return true;
57 } 60 }
58 61
59 bool RequestManager::RejectRequest(const ProvidedFileSystem& file_system, 62 bool RequestManager::RejectRequest(const std::string& extension_id,
63 int file_system_id,
60 int request_id, 64 int request_id,
61 base::File::Error error) { 65 base::File::Error error) {
62 RequestMap::iterator request_it = requests_.find(request_id); 66 RequestMap::iterator request_it = requests_.find(request_id);
63 67
64 if (request_it == requests_.end()) 68 if (request_it == requests_.end())
65 return false; 69 return false;
66 70
67 // Check if the request belongs to the same provided file system. 71 // Check if the request belongs to the same provided file system.
68 if (request_it->second.file_system.file_system_id() != 72 if (request_it->second.file_system_id != file_system_id ||
69 file_system.file_system_id()) { 73 request_it->second.extension_id != extension_id) {
70 return false; 74 return false;
71 } 75 }
72 76
73 if (!request_it->second.error_callback.is_null()) 77 if (!request_it->second.error_callback.is_null())
74 request_it->second.error_callback.Run(error); 78 request_it->second.error_callback.Run(error);
75 requests_.erase(request_it); 79 requests_.erase(request_it);
76 80
77 return true; 81 return true;
78 } 82 }
79 83
80 void RequestManager::OnProvidedFileSystemMount( 84 void RequestManager::OnProvidedFileSystemMount(
81 const ProvidedFileSystem& file_system, 85 const ProvidedFileSystemInfo& file_system_info,
82 base::File::Error error) {} 86 base::File::Error error) {}
83 87
84 void RequestManager::OnProvidedFileSystemUnmount( 88 void RequestManager::OnProvidedFileSystemUnmount(
85 const ProvidedFileSystem& file_system, 89 const ProvidedFileSystemInfo& file_system_info,
86 base::File::Error error) { 90 base::File::Error error) {
87 // Do not continue on error, since the volume may be still mounted. 91 // Do not continue on error, since the volume may be still mounted.
88 if (error != base::File::FILE_OK) 92 if (error != base::File::FILE_OK)
89 return; 93 return;
90 94
91 // Remove all requests for this provided file system. 95 // Remove all requests for this provided file system.
92 RequestMap::iterator it = requests_.begin(); 96 RequestMap::iterator it = requests_.begin();
93 while (it != requests_.begin()) { 97 while (it != requests_.begin()) {
94 if (it->second.file_system.file_system_id() == 98 if (it->second.file_system_id == file_system_info.file_system_id() &&
95 file_system.file_system_id()) { 99 it->second.extension_id == file_system_info.extension_id()) {
96 RejectRequest( 100 RejectRequest(it->second.extension_id,
97 it->second.file_system, it->first, base::File::FILE_ERROR_ABORT); 101 it->second.file_system_id,
102 it->first,
103 base::File::FILE_ERROR_ABORT);
98 requests_.erase(it++); 104 requests_.erase(it++);
99 } else { 105 } else {
100 it++; 106 ++it;
101 } 107 }
102 } 108 }
103 } 109 }
104 110
105 RequestManager::Request::Request() {} 111 RequestManager::Request::Request() : file_system_id(0) {}
106 112
107 RequestManager::Request::~Request() {} 113 RequestManager::Request::~Request() {}
108 114
109 } // namespace file_system_provider 115 } // namespace file_system_provider
110 } // namespace chromeos 116 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698