OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/drive/drive_api_service.h" | 5 #include "chrome/browser/chromeos/drive/drive_api_service.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 google_apis::ResourceList::CreateFromChangeList(*change_list); | 54 google_apis::ResourceList::CreateFromChangeList(*change_list); |
55 if (!resource_list) { | 55 if (!resource_list) { |
56 callback.Run(google_apis::GDATA_PARSE_ERROR, | 56 callback.Run(google_apis::GDATA_PARSE_ERROR, |
57 scoped_ptr<google_apis::ResourceList>()); | 57 scoped_ptr<google_apis::ResourceList>()); |
58 return; | 58 return; |
59 } | 59 } |
60 | 60 |
61 callback.Run(error, resource_list.Pass()); | 61 callback.Run(error, resource_list.Pass()); |
62 } | 62 } |
63 | 63 |
| 64 // Parses the JSON value to ResourceEntry runs |callback|. |
| 65 void ParseResourceEntryAndRun( |
| 66 const google_apis::GetResourceEntryCallback& callback, |
| 67 google_apis::GDataErrorCode error, |
| 68 scoped_ptr<base::Value> value) { |
| 69 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 70 |
| 71 if (!value) { |
| 72 callback.Run(error, scoped_ptr<google_apis::ResourceEntry>()); |
| 73 return; |
| 74 } |
| 75 |
| 76 // Parsing FileResource is cheap enough to do on UI thread. |
| 77 scoped_ptr<google_apis::FileResource> file_resource = |
| 78 google_apis::FileResource::CreateFrom(*value); |
| 79 if (!file_resource) { |
| 80 callback.Run(google_apis::GDATA_PARSE_ERROR, |
| 81 scoped_ptr<google_apis::ResourceEntry>()); |
| 82 return; |
| 83 } |
| 84 |
| 85 // Converting to ResourceEntry is cheap enough to do on UI thread. |
| 86 scoped_ptr<google_apis::ResourceEntry> entry = |
| 87 google_apis::ResourceEntry::CreateFromFileResource(*file_resource); |
| 88 if (!entry) { |
| 89 callback.Run(google_apis::GDATA_PARSE_ERROR, |
| 90 scoped_ptr<google_apis::ResourceEntry>()); |
| 91 return; |
| 92 } |
| 93 |
| 94 callback.Run(error, entry.Pass()); |
| 95 } |
| 96 |
64 } // namespace | 97 } // namespace |
65 | 98 |
66 DriveAPIService::DriveAPIService( | 99 DriveAPIService::DriveAPIService( |
67 net::URLRequestContextGetter* url_request_context_getter, | 100 net::URLRequestContextGetter* url_request_context_getter, |
68 const std::string& custom_user_agent) | 101 const std::string& custom_user_agent) |
69 : url_request_context_getter_(url_request_context_getter), | 102 : url_request_context_getter_(url_request_context_getter), |
70 profile_(NULL), | 103 profile_(NULL), |
71 runner_(NULL), | 104 runner_(NULL), |
72 custom_user_agent_(custom_user_agent) { | 105 custom_user_agent_(custom_user_agent) { |
73 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 new google_apis::GetChangelistOperation( | 210 new google_apis::GetChangelistOperation( |
178 operation_registry(), | 211 operation_registry(), |
179 url_request_context_getter_, | 212 url_request_context_getter_, |
180 url, | 213 url, |
181 start_changestamp, | 214 start_changestamp, |
182 base::Bind(&ParseResourceListAndRun, callback))); | 215 base::Bind(&ParseResourceListAndRun, callback))); |
183 } | 216 } |
184 | 217 |
185 void DriveAPIService::GetResourceEntry( | 218 void DriveAPIService::GetResourceEntry( |
186 const std::string& resource_id, | 219 const std::string& resource_id, |
187 const google_apis::GetDataCallback& callback) { | 220 const google_apis::GetResourceEntryCallback& callback) { |
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
189 DCHECK(!callback.is_null()); | 222 DCHECK(!callback.is_null()); |
190 | 223 |
191 runner_->StartOperationWithRetry(new google_apis::GetFileOperation( | 224 runner_->StartOperationWithRetry(new google_apis::GetFileOperation( |
192 operation_registry(), | 225 operation_registry(), |
193 url_request_context_getter_, | 226 url_request_context_getter_, |
194 resource_id, | 227 resource_id, |
195 callback)); | 228 base::Bind(&ParseResourceEntryAndRun, callback))); |
196 } | 229 } |
197 | 230 |
198 void DriveAPIService::GetAccountMetadata( | 231 void DriveAPIService::GetAccountMetadata( |
199 const google_apis::GetDataCallback& callback) { | 232 const google_apis::GetDataCallback& callback) { |
200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
201 DCHECK(!callback.is_null()); | 234 DCHECK(!callback.is_null()); |
202 | 235 |
203 runner_->StartOperationWithRetry( | 236 runner_->StartOperationWithRetry( |
204 new google_apis::GetAboutOperation(operation_registry(), | 237 new google_apis::GetAboutOperation(operation_registry(), |
205 url_request_context_getter_, | 238 url_request_context_getter_, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 407 |
375 void DriveAPIService::OnAuthenticationFailed( | 408 void DriveAPIService::OnAuthenticationFailed( |
376 google_apis::GDataErrorCode error) { | 409 google_apis::GDataErrorCode error) { |
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
378 FOR_EACH_OBSERVER( | 411 FOR_EACH_OBSERVER( |
379 google_apis::DriveServiceObserver, observers_, | 412 google_apis::DriveServiceObserver, observers_, |
380 OnAuthenticationFailed(error)); | 413 OnAuthenticationFailed(error)); |
381 } | 414 } |
382 | 415 |
383 } // namespace drive | 416 } // namespace drive |
OLD | NEW |