| OLD | NEW |
| 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 "sync/internal_api/public/attachments/attachment_uploader_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } | 83 } |
| 84 | 84 |
| 85 protected: | 85 protected: |
| 86 void FetchOAuth2Token(RequestImpl* request, | 86 void FetchOAuth2Token(RequestImpl* request, |
| 87 const std::string& account_id, | 87 const std::string& account_id, |
| 88 net::URLRequestContextGetter* getter, | 88 net::URLRequestContextGetter* getter, |
| 89 const std::string& client_id, | 89 const std::string& client_id, |
| 90 const std::string& client_secret, | 90 const std::string& client_secret, |
| 91 const ScopeSet& scopes) override; | 91 const ScopeSet& scopes) override; |
| 92 | 92 |
| 93 void InvalidateOAuth2Token(const std::string& account_id, | 93 void InvalidateAccessTokenImpl(const std::string& account_id, |
| 94 const std::string& client_id, | 94 const std::string& client_id, |
| 95 const ScopeSet& scopes, | 95 const ScopeSet& scopes, |
| 96 const std::string& access_token) override; | 96 const std::string& access_token) override; |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 GoogleServiceAuthError response_error_; | 99 GoogleServiceAuthError response_error_; |
| 100 std::string response_access_token_; | 100 std::string response_access_token_; |
| 101 base::Time response_expiration_; | 101 base::Time response_expiration_; |
| 102 int num_invalidate_token_; | 102 int num_invalidate_token_; |
| 103 std::string last_token_invalidated_; | 103 std::string last_token_invalidated_; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 MockOAuth2TokenService::MockOAuth2TokenService() | 106 MockOAuth2TokenService::MockOAuth2TokenService() |
| (...skipping 23 matching lines...) Expand all Loading... |
| 130 const ScopeSet& scopes) { | 130 const ScopeSet& scopes) { |
| 131 base::MessageLoop::current()->PostTask( | 131 base::MessageLoop::current()->PostTask( |
| 132 FROM_HERE, | 132 FROM_HERE, |
| 133 base::Bind(&OAuth2TokenService::RequestImpl::InformConsumer, | 133 base::Bind(&OAuth2TokenService::RequestImpl::InformConsumer, |
| 134 request->AsWeakPtr(), | 134 request->AsWeakPtr(), |
| 135 response_error_, | 135 response_error_, |
| 136 response_access_token_, | 136 response_access_token_, |
| 137 response_expiration_)); | 137 response_expiration_)); |
| 138 } | 138 } |
| 139 | 139 |
| 140 void MockOAuth2TokenService::InvalidateOAuth2Token( | 140 void MockOAuth2TokenService::InvalidateAccessTokenImpl( |
| 141 const std::string& account_id, | 141 const std::string& account_id, |
| 142 const std::string& client_id, | 142 const std::string& client_id, |
| 143 const ScopeSet& scopes, | 143 const ScopeSet& scopes, |
| 144 const std::string& access_token) { | 144 const std::string& access_token) { |
| 145 ++num_invalidate_token_; | 145 ++num_invalidate_token_; |
| 146 last_token_invalidated_ = access_token; | 146 last_token_invalidated_ = access_token; |
| 147 } | 147 } |
| 148 | 148 |
| 149 class TokenServiceProvider | 149 class TokenServiceProvider |
| 150 : public OAuth2TokenServiceRequest::TokenServiceProvider, | 150 : public OAuth2TokenServiceRequest::TokenServiceProvider, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 for (int i = 0; i < num_uploads; ++i) { | 311 for (int i = 0; i < num_uploads; ++i) { |
| 312 // Run the loop until one upload completes. | 312 // Run the loop until one upload completes. |
| 313 base::RunLoop run_loop; | 313 base::RunLoop run_loop; |
| 314 signal_upload_done_ = run_loop.QuitClosure(); | 314 signal_upload_done_ = run_loop.QuitClosure(); |
| 315 run_loop.Run(); | 315 run_loop.Run(); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 Attachment AttachmentUploaderImplTest::UploadAndRespondWith( | 319 Attachment AttachmentUploaderImplTest::UploadAndRespondWith( |
| 320 const net::HttpStatusCode& status_code) { | 320 const net::HttpStatusCode& status_code) { |
| 321 token_service().AddAccount(kAccountId); | 321 token_service().GetDelegate()->UpdateCredentials(kAccountId, "refresh_token"); |
| 322 request_handler().SetStatusCode(status_code); | 322 request_handler().SetStatusCode(status_code); |
| 323 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); | 323 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString); |
| 324 some_data->data() = kAttachmentData; | 324 some_data->data() = kAttachmentData; |
| 325 Attachment attachment = Attachment::Create(some_data); | 325 Attachment attachment = Attachment::Create(some_data); |
| 326 uploader()->UploadAttachment(attachment, upload_callback()); | 326 uploader()->UploadAttachment(attachment, upload_callback()); |
| 327 return attachment; | 327 return attachment; |
| 328 } | 328 } |
| 329 | 329 |
| 330 scoped_ptr<AttachmentUploader>& AttachmentUploaderImplTest::uploader() { | 330 scoped_ptr<AttachmentUploader>& AttachmentUploaderImplTest::uploader() { |
| 331 return uploader_; | 331 return uploader_; |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); | 671 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); |
| 672 hello_world->data() = "hello world"; | 672 hello_world->data() = "hello world"; |
| 673 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( | 673 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( |
| 674 ComputeCrc32c(hello_world))); | 674 ComputeCrc32c(hello_world))); |
| 675 } | 675 } |
| 676 | 676 |
| 677 // TODO(maniscalco): Add test case for when we are uploading an attachment that | 677 // TODO(maniscalco): Add test case for when we are uploading an attachment that |
| 678 // already exists. 409 Conflict? (bug 379825) | 678 // already exists. 409 Conflict? (bug 379825) |
| 679 | 679 |
| 680 } // namespace syncer | 680 } // namespace syncer |
| OLD | NEW |