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

Side by Side Diff: sync/internal_api/attachments/attachment_uploader_impl_unittest.cc

Issue 458753006: Fix use after free bug by calling GetTokenService in Core's ctor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update TSP comment (CANDIDATE). Created 6 years, 4 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 "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/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 const std::string& access_token) { 128 const std::string& access_token) {
129 ++num_invalidate_token_; 129 ++num_invalidate_token_;
130 last_token_invalidated_ = access_token; 130 last_token_invalidated_ = access_token;
131 } 131 }
132 132
133 class TokenServiceProvider 133 class TokenServiceProvider
134 : public OAuth2TokenServiceRequest::TokenServiceProvider, 134 : public OAuth2TokenServiceRequest::TokenServiceProvider,
135 base::NonThreadSafe { 135 base::NonThreadSafe {
136 public: 136 public:
137 TokenServiceProvider(OAuth2TokenService* token_service); 137 TokenServiceProvider(OAuth2TokenService* token_service);
138 virtual ~TokenServiceProvider();
139 138
140 // OAuth2TokenService::TokenServiceProvider implementation. 139 // OAuth2TokenService::TokenServiceProvider implementation.
141 virtual scoped_refptr<base::SingleThreadTaskRunner> 140 virtual scoped_refptr<base::SingleThreadTaskRunner>
142 GetTokenServiceTaskRunner() OVERRIDE; 141 GetTokenServiceTaskRunner() OVERRIDE;
143 virtual OAuth2TokenService* GetTokenService() OVERRIDE; 142 virtual OAuth2TokenService* GetTokenService() OVERRIDE;
144 143
145 private: 144 private:
145 virtual ~TokenServiceProvider();
146
146 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 147 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
147 OAuth2TokenService* token_service_; 148 OAuth2TokenService* token_service_;
148 }; 149 };
149 150
150 TokenServiceProvider::TokenServiceProvider(OAuth2TokenService* token_service) 151 TokenServiceProvider::TokenServiceProvider(OAuth2TokenService* token_service)
151 : task_runner_(base::ThreadTaskRunnerHandle::Get()), 152 : task_runner_(base::ThreadTaskRunnerHandle::Get()),
152 token_service_(token_service) { 153 token_service_(token_service) {
153 DCHECK(token_service_); 154 DCHECK(token_service_);
154 } 155 }
155 156
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy()); 262 new net::TestURLRequestContextGetter(message_loop_.message_loop_proxy());
262 263
263 ASSERT_TRUE(server_.InitializeAndWaitUntilReady()); 264 ASSERT_TRUE(server_.InitializeAndWaitUntilReady());
264 server_.RegisterRequestHandler( 265 server_.RegisterRequestHandler(
265 base::Bind(&RequestHandler::HandleRequest, 266 base::Bind(&RequestHandler::HandleRequest,
266 base::Unretained(request_handler_.get()))); 267 base::Unretained(request_handler_.get())));
267 268
268 GURL url(base::StringPrintf("http://localhost:%d/", server_.port())); 269 GURL url(base::StringPrintf("http://localhost:%d/", server_.port()));
269 270
270 token_service_.reset(new MockOAuth2TokenService); 271 token_service_.reset(new MockOAuth2TokenService);
271 scoped_ptr<OAuth2TokenServiceRequest::TokenServiceProvider> 272 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider>
272 token_service_provider(new TokenServiceProvider(token_service_.get())); 273 token_service_provider(new TokenServiceProvider(token_service_.get()));
273 274
274 OAuth2TokenService::ScopeSet scopes; 275 OAuth2TokenService::ScopeSet scopes;
275 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); 276 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope);
276 uploader().reset(new AttachmentUploaderImpl(url, 277 uploader().reset(new AttachmentUploaderImpl(url,
277 url_request_context_getter_, 278 url_request_context_getter_,
278 kAccountId, 279 kAccountId,
279 scopes, 280 scopes,
280 token_service_provider.Pass())); 281 token_service_provider));
281 282
282 upload_callback_ = base::Bind(&AttachmentUploaderImplTest::UploadDone, 283 upload_callback_ = base::Bind(&AttachmentUploaderImplTest::UploadDone,
283 base::Unretained(this)); 284 base::Unretained(this));
284 } 285 }
285 286
286 void AttachmentUploaderImplTest::TearDown() { 287 void AttachmentUploaderImplTest::TearDown() {
287 base::RunLoop().RunUntilIdle(); 288 base::RunLoop().RunUntilIdle();
288 } 289 }
289 290
290 void AttachmentUploaderImplTest::RunAndWaitFor(int num_uploads) { 291 void AttachmentUploaderImplTest::RunAndWaitFor(int num_uploads) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 testing::Contains(testing::Pair(header_name, header_value))); 589 testing::Contains(testing::Pair(header_name, header_value)));
589 590
590 // See that we invalidated the token. 591 // See that we invalidated the token.
591 ASSERT_EQ(1, token_service().num_invalidate_token()); 592 ASSERT_EQ(1, token_service().num_invalidate_token());
592 } 593 }
593 594
594 // TODO(maniscalco): Add test case for when we are uploading an attachment that 595 // TODO(maniscalco): Add test case for when we are uploading an attachment that
595 // already exists. 409 Conflict? (bug 379825) 596 // already exists. 409 Conflict? (bug 379825)
596 597
597 } // namespace syncer 598 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698