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

Side by Side Diff: components/ntp_snippets/ntp_snippets_database.cc

Issue 2368583002: [NTP Snippets] Cleanups from clang-tidy (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
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 "components/ntp_snippets/ntp_snippets_database.h" 5 #include "components/ntp_snippets/ntp_snippets_database.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "components/leveldb_proto/proto_database_impl.h" 10 #include "components/leveldb_proto/proto_database_impl.h"
11 #include "components/ntp_snippets/proto/ntp_snippets.pb.h" 11 #include "components/ntp_snippets/proto/ntp_snippets.pb.h"
12 12
13 using leveldb_proto::ProtoDatabaseImpl; 13 using leveldb_proto::ProtoDatabaseImpl;
14 14
15 namespace { 15 namespace {
16 // Statistics are logged to UMA with this string as part of histogram name. They 16 // Statistics are logged to UMA with this string as part of histogram name. They
17 // can all be found under LevelDB.*.NTPSnippets. Changing this needs to 17 // can all be found under LevelDB.*.NTPSnippets. Changing this needs to
18 // synchronize with histograms.xml, AND will also become incompatible with older 18 // synchronize with histograms.xml, AND will also become incompatible with older
19 // browsers still reporting the previous values. 19 // browsers still reporting the previous values.
20 const char kDatabaseUMAClientName[] = "NTPSnippets"; 20 const char kDatabaseUMAClientName[] = "NTPSnippets";
21 const char kImageDatabaseUMAClientName[] = "NTPSnippetImages"; 21 const char kImageDatabaseUMAClientName[] = "NTPSnippetImages";
22 22
23 const char kSnippetDatabaseFolder[] = "snippets"; 23 const char kSnippetDatabaseFolder[] = "snippets";
24 const char kImageDatabaseFolder[] = "images"; 24 const char kImageDatabaseFolder[] = "images";
25 } 25 } // namespace
26 26
27 namespace ntp_snippets { 27 namespace ntp_snippets {
28 28
29 NTPSnippetsDatabase::NTPSnippetsDatabase( 29 NTPSnippetsDatabase::NTPSnippetsDatabase(
30 const base::FilePath& database_dir, 30 const base::FilePath& database_dir,
31 scoped_refptr<base::SequencedTaskRunner> file_task_runner) 31 scoped_refptr<base::SequencedTaskRunner> file_task_runner)
32 : database_( 32 : database_(
33 new ProtoDatabaseImpl<SnippetProto>(file_task_runner)), 33 new ProtoDatabaseImpl<SnippetProto>(file_task_runner)),
34 database_initialized_(false), 34 database_initialized_(false),
35 image_database_( 35 image_database_(
36 new ProtoDatabaseImpl<SnippetImageProto>(file_task_runner)), 36 new ProtoDatabaseImpl<SnippetImageProto>(file_task_runner)),
37 image_database_initialized_(false), 37 image_database_initialized_(false),
38 weak_ptr_factory_(this) { 38 weak_ptr_factory_(this) {
39 base::FilePath snippet_dir = database_dir.AppendASCII(kSnippetDatabaseFolder); 39 base::FilePath snippet_dir = database_dir.AppendASCII(kSnippetDatabaseFolder);
40 database_->Init(kDatabaseUMAClientName, snippet_dir, 40 database_->Init(kDatabaseUMAClientName, snippet_dir,
41 base::Bind(&NTPSnippetsDatabase::OnDatabaseInited, 41 base::Bind(&NTPSnippetsDatabase::OnDatabaseInited,
42 weak_ptr_factory_.GetWeakPtr())); 42 weak_ptr_factory_.GetWeakPtr()));
43 43
44 base::FilePath image_dir = database_dir.AppendASCII(kImageDatabaseFolder); 44 base::FilePath image_dir = database_dir.AppendASCII(kImageDatabaseFolder);
45 image_database_->Init(kImageDatabaseUMAClientName, image_dir, 45 image_database_->Init(kImageDatabaseUMAClientName, image_dir,
46 base::Bind(&NTPSnippetsDatabase::OnImageDatabaseInited, 46 base::Bind(&NTPSnippetsDatabase::OnImageDatabaseInited,
47 weak_ptr_factory_.GetWeakPtr())); 47 weak_ptr_factory_.GetWeakPtr()));
48 } 48 }
49 49
50 NTPSnippetsDatabase::~NTPSnippetsDatabase() {} 50 NTPSnippetsDatabase::~NTPSnippetsDatabase() = default;
51 51
52 bool NTPSnippetsDatabase::IsInitialized() const { 52 bool NTPSnippetsDatabase::IsInitialized() const {
53 return !IsErrorState() && database_initialized_ && 53 return !IsErrorState() && database_initialized_ &&
54 image_database_initialized_; 54 image_database_initialized_;
55 } 55 }
56 56
57 bool NTPSnippetsDatabase::IsErrorState() const { 57 bool NTPSnippetsDatabase::IsErrorState() const {
58 return !database_ || !image_database_; 58 return !database_ || !image_database_;
59 } 59 }
60 60
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 std::unique_ptr<std::vector<std::string>> keys_to_remove) { 278 std::unique_ptr<std::vector<std::string>> keys_to_remove) {
279 DCHECK(IsInitialized()); 279 DCHECK(IsInitialized());
280 280
281 image_database_->UpdateEntries( 281 image_database_->UpdateEntries(
282 base::MakeUnique<ImageKeyEntryVector>(), std::move(keys_to_remove), 282 base::MakeUnique<ImageKeyEntryVector>(), std::move(keys_to_remove),
283 base::Bind(&NTPSnippetsDatabase::OnImageDatabaseSaved, 283 base::Bind(&NTPSnippetsDatabase::OnImageDatabaseSaved,
284 weak_ptr_factory_.GetWeakPtr())); 284 weak_ptr_factory_.GetWeakPtr()));
285 } 285 }
286 286
287 } // namespace ntp_snippets 287 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698