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

Side by Side Diff: cc/layers/delegated_frame_resource_collection.cc

Issue 47703005: Fix DelegatedFrameResourceCollection thread safety (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "cc/layers/delegated_frame_resource_collection.h" 5 #include "cc/layers/delegated_frame_resource_collection.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "cc/trees/blocking_task_runner.h" 8 #include "cc/trees/blocking_task_runner.h"
9 9
10 namespace cc { 10 namespace cc {
11 11
12 DelegatedFrameResourceCollection::DelegatedFrameResourceCollection() 12 DelegatedFrameResourceCollection::DelegatedFrameResourceCollection()
13 : client_(NULL), 13 : client_(NULL),
14 main_thread_runner_(BlockingTaskRunner::current()), 14 main_thread_runner_(BlockingTaskRunner::current()),
15 lost_all_resources_(false) { 15 lost_all_resources_(false),
16 weak_ptr_factory_(this) {
16 DCHECK(main_thread_checker_.CalledOnValidThread()); 17 DCHECK(main_thread_checker_.CalledOnValidThread());
17 } 18 }
18 19
19 DelegatedFrameResourceCollection::~DelegatedFrameResourceCollection() { 20 DelegatedFrameResourceCollection::~DelegatedFrameResourceCollection() {
20 DCHECK(main_thread_checker_.CalledOnValidThread()); 21 DCHECK(main_thread_checker_.CalledOnValidThread());
21 } 22 }
22 23
23 void DelegatedFrameResourceCollection::SetClient( 24 void DelegatedFrameResourceCollection::SetClient(
24 DelegatedFrameResourceCollectionClient* client) { 25 DelegatedFrameResourceCollectionClient* client) {
25 client_ = client; 26 client_ = client;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 client_->UnusedResourcesAreAvailable(); 106 client_->UnusedResourcesAreAvailable();
106 } 107 }
107 108
108 void DelegatedFrameResourceCollection::RefResources( 109 void DelegatedFrameResourceCollection::RefResources(
109 const TransferableResourceArray& resources) { 110 const TransferableResourceArray& resources) {
110 DCHECK(main_thread_checker_.CalledOnValidThread()); 111 DCHECK(main_thread_checker_.CalledOnValidThread());
111 for (size_t i = 0; i < resources.size(); ++i) 112 for (size_t i = 0; i < resources.size(); ++i)
112 resource_id_ref_count_map_[resources[i].id].refs_to_wait_for++; 113 resource_id_ref_count_map_[resources[i].id].refs_to_wait_for++;
113 } 114 }
114 115
115 ReturnCallback 116 static void UnrefResourcesOnImplThread(
116 DelegatedFrameResourceCollection::GetReturnResourcesCallbackForImplThread() { 117 base::WeakPtr<DelegatedFrameResourceCollection> self,
117 return base::Bind(
118 &DelegatedFrameResourceCollection::UnrefResourcesOnImplThread,
119 this,
120 main_thread_runner_);
121 }
122
123 void DelegatedFrameResourceCollection::UnrefResourcesOnImplThread(
124 scoped_refptr<BlockingTaskRunner> main_thread_runner, 118 scoped_refptr<BlockingTaskRunner> main_thread_runner,
125 const ReturnedResourceArray& returned) { 119 const ReturnedResourceArray& returned) {
126 main_thread_runner->PostTask( 120 main_thread_runner->PostTask(
127 FROM_HERE, 121 FROM_HERE,
128 base::Bind( 122 base::Bind(
129 &DelegatedFrameResourceCollection::UnrefResources, this, returned)); 123 &DelegatedFrameResourceCollection::UnrefResources, self, returned));
124 }
125
126 ReturnCallback
127 DelegatedFrameResourceCollection::GetReturnResourcesCallbackForImplThread() {
128 return base::Bind(&UnrefResourcesOnImplThread,
129 weak_ptr_factory_.GetWeakPtr(),
130 main_thread_runner_);
130 } 131 }
131 132
132 } // namespace cc 133 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/delegated_frame_resource_collection.h ('k') | cc/layers/delegated_frame_resource_collection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698