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/google_apis/gdata_wapi_service.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 scoped_ptr<ResourceEntry> entry = | 98 scoped_ptr<ResourceEntry> entry = |
99 google_apis::ResourceEntry::ExtractAndParse(*value); | 99 google_apis::ResourceEntry::ExtractAndParse(*value); |
100 if (!entry) { | 100 if (!entry) { |
101 callback.Run(GDATA_PARSE_ERROR, scoped_ptr<ResourceEntry>()); | 101 callback.Run(GDATA_PARSE_ERROR, scoped_ptr<ResourceEntry>()); |
102 return; | 102 return; |
103 } | 103 } |
104 | 104 |
105 callback.Run(error, entry.Pass()); | 105 callback.Run(error, entry.Pass()); |
106 } | 106 } |
107 | 107 |
108 // Extracts the open link url from the JSON Feed. Used by AuthorizeApp(). | |
109 void ExtractOpenLinkAndRun(const std::string app_id, | |
110 const AuthorizeAppCallback& callback, | |
111 GDataErrorCode error, | |
112 scoped_ptr<ResourceEntry> entry) { | |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
114 | |
115 // Entry not found in the feed. | |
116 if (!entry) { | |
117 callback.Run(error, GURL()); | |
118 return; | |
119 } | |
120 | |
121 const ScopedVector<google_apis::Link>& resource_links = entry->links(); | |
122 GURL open_link; | |
123 for (size_t i = 0; i < resource_links.size(); ++i) { | |
124 if (resource_links[i]->type() == google_apis::Link::LINK_OPEN_WITH && | |
125 resource_links[i]->app_id() == app_id) { | |
126 open_link = resource_links[i]->href(); | |
127 break; | |
128 } | |
129 } | |
130 | |
131 callback.Run(error, open_link); | |
132 } | |
133 | |
134 void ParseAboutResourceAndRun( | 108 void ParseAboutResourceAndRun( |
135 const GetAboutResourceCallback& callback, | 109 const GetAboutResourceCallback& callback, |
136 GDataErrorCode error, | 110 GDataErrorCode error, |
137 scoped_ptr<AccountMetadata> account_metadata) { | 111 scoped_ptr<AccountMetadata> account_metadata) { |
138 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
139 DCHECK(!callback.is_null()); | 113 DCHECK(!callback.is_null()); |
140 | 114 |
141 scoped_ptr<AboutResource> about_resource; | 115 scoped_ptr<AboutResource> about_resource; |
142 if (account_metadata) { | 116 if (account_metadata) { |
143 about_resource = AboutResource::CreateFromAccountMetadata( | 117 about_resource = AboutResource::CreateFromAccountMetadata( |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 const std::string& app_id, | 508 const std::string& app_id, |
535 const AuthorizeAppCallback& callback) { | 509 const AuthorizeAppCallback& callback) { |
536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
537 DCHECK(!callback.is_null()); | 511 DCHECK(!callback.is_null()); |
538 | 512 |
539 runner_->StartOperationWithRetry( | 513 runner_->StartOperationWithRetry( |
540 new AuthorizeAppOperation( | 514 new AuthorizeAppOperation( |
541 operation_registry(), | 515 operation_registry(), |
542 url_request_context_getter_, | 516 url_request_context_getter_, |
543 url_generator_, | 517 url_generator_, |
544 base::Bind(&ParseResourceEntryAndRun, | 518 callback, |
545 base::Bind(&ExtractOpenLinkAndRun, app_id, callback)), | |
546 resource_id, | 519 resource_id, |
547 app_id)); | 520 app_id)); |
548 } | 521 } |
549 | 522 |
550 bool GDataWapiService::HasAccessToken() const { | 523 bool GDataWapiService::HasAccessToken() const { |
551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
552 | 525 |
553 return runner_->auth_service()->HasAccessToken(); | 526 return runner_->auth_service()->HasAccessToken(); |
554 } | 527 } |
555 | 528 |
(...skipping 29 matching lines...) Expand all Loading... |
585 } | 558 } |
586 | 559 |
587 void GDataWapiService::OnProgressUpdate( | 560 void GDataWapiService::OnProgressUpdate( |
588 const OperationProgressStatusList& list) { | 561 const OperationProgressStatusList& list) { |
589 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 562 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
590 FOR_EACH_OBSERVER( | 563 FOR_EACH_OBSERVER( |
591 DriveServiceObserver, observers_, OnProgressUpdate(list)); | 564 DriveServiceObserver, observers_, OnProgressUpdate(list)); |
592 } | 565 } |
593 | 566 |
594 } // namespace google_apis | 567 } // namespace google_apis |
OLD | NEW |