| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/debug/leak_annotations.h" | 8 #include "base/debug/leak_annotations.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "components/safe_browsing_db/v4_database.h" | 12 #include "components/safe_browsing_db/v4_database.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 | 14 |
| 15 using content::BrowserThread; | 15 using content::BrowserThread; |
| 16 | 16 |
| 17 namespace safe_browsing { | 17 namespace safe_browsing { |
| 18 | 18 |
| 19 // static | 19 // static |
| 20 V4StoreFactory* V4Database::factory_ = NULL; | 20 V4StoreFactory* V4Database::factory_ = NULL; |
| 21 | 21 |
| 22 // static | 22 // static |
| 23 void V4Database::Create( | 23 void V4Database::Create( |
| 24 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 24 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 25 const base::FilePath& base_path, | 25 const base::FilePath& base_path, |
| 26 const ListInfos& list_infos, | 26 const ListInfos& list_infos, |
| 27 NewDatabaseReadyCallback new_db_callback) { | 27 NewDatabaseReadyCallback new_db_callback) { |
| 28 DCHECK(base_path.IsAbsolute()); | 28 DCHECK(base_path.IsAbsolute()); |
| 29 DCHECK(!list_infos.empty()); | 29 DCHECK(!list_infos.empty()); |
| 30 | 30 |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner = | 31 const scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner = |
| 32 base::MessageLoop::current()->task_runner(); | 32 base::ThreadTaskRunnerHandle::Get(); |
| 33 db_task_runner->PostTask( | 33 db_task_runner->PostTask( |
| 34 FROM_HERE, | 34 FROM_HERE, |
| 35 base::Bind(&V4Database::CreateOnTaskRunner, db_task_runner, base_path, | 35 base::Bind(&V4Database::CreateOnTaskRunner, db_task_runner, base_path, |
| 36 list_infos, callback_task_runner, new_db_callback)); | 36 list_infos, callback_task_runner, new_db_callback)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 // static | 39 // static |
| 40 void V4Database::CreateOnTaskRunner( | 40 void V4Database::CreateOnTaskRunner( |
| 41 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, | 41 const scoped_refptr<base::SequencedTaskRunner>& db_task_runner, |
| 42 const base::FilePath& base_path, | 42 const base::FilePath& base_path, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 std::unique_ptr<ParsedServerResponse> parsed_server_response, | 100 std::unique_ptr<ParsedServerResponse> parsed_server_response, |
| 101 DatabaseUpdatedCallback db_updated_callback) { | 101 DatabaseUpdatedCallback db_updated_callback) { |
| 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 102 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 103 DCHECK(!pending_store_updates_); | 103 DCHECK(!pending_store_updates_); |
| 104 DCHECK(db_updated_callback_.is_null()); | 104 DCHECK(db_updated_callback_.is_null()); |
| 105 | 105 |
| 106 db_updated_callback_ = db_updated_callback; | 106 db_updated_callback_ = db_updated_callback; |
| 107 | 107 |
| 108 // Post the V4Store update task on the task runner but get the callback on the | 108 // Post the V4Store update task on the task runner but get the callback on the |
| 109 // current thread. | 109 // current thread. |
| 110 const scoped_refptr<base::SingleThreadTaskRunner>& current_task_runner = | 110 const scoped_refptr<base::SingleThreadTaskRunner> current_task_runner = |
| 111 base::MessageLoop::current()->task_runner(); | 111 base::ThreadTaskRunnerHandle::Get(); |
| 112 for (std::unique_ptr<ListUpdateResponse>& response : | 112 for (std::unique_ptr<ListUpdateResponse>& response : |
| 113 *parsed_server_response) { | 113 *parsed_server_response) { |
| 114 ListIdentifier identifier(*response); | 114 ListIdentifier identifier(*response); |
| 115 StoreMap::const_iterator iter = store_map_->find(identifier); | 115 StoreMap::const_iterator iter = store_map_->find(identifier); |
| 116 if (iter != store_map_->end()) { | 116 if (iter != store_map_->end()) { |
| 117 const std::unique_ptr<V4Store>& old_store = iter->second; | 117 const std::unique_ptr<V4Store>& old_store = iter->second; |
| 118 if (old_store->state() != response->new_client_state()) { | 118 if (old_store->state() != response->new_client_state()) { |
| 119 // A different state implies there are updates to process. | 119 // A different state implies there are updates to process. |
| 120 pending_store_updates_++; | 120 pending_store_updates_++; |
| 121 UpdatedStoreReadyCallback store_ready_callback = base::Bind( | 121 UpdatedStoreReadyCallback store_ready_callback = base::Bind( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 filename_(filename), | 197 filename_(filename), |
| 198 list_id_(list_id), | 198 list_id_(list_id), |
| 199 sb_threat_type_(sb_threat_type) { | 199 sb_threat_type_(sb_threat_type) { |
| 200 DCHECK(!fetch_updates_ || !filename_.empty()); | 200 DCHECK(!fetch_updates_ || !filename_.empty()); |
| 201 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); | 201 DCHECK_NE(SB_THREAT_TYPE_SAFE, sb_threat_type_); |
| 202 } | 202 } |
| 203 | 203 |
| 204 ListInfo::~ListInfo() {} | 204 ListInfo::~ListInfo() {} |
| 205 | 205 |
| 206 } // namespace safe_browsing | 206 } // namespace safe_browsing |
| OLD | NEW |