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

Side by Side Diff: chrome/browser/ui/app_list/search/history.cc

Issue 518293002: App-list history cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test fix Created 6 years, 3 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 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 "chrome/browser/ui/app_list/search/history.h" 5 #include "chrome/browser/ui/app_list/search/history.h"
6 6
7 #include "base/files/file_path.h"
8 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/app_list/search/history_data.h" 9 #include "chrome/browser/ui/app_list/search/history_data.h"
11 #include "chrome/browser/ui/app_list/search/history_data_store.h" 10 #include "chrome/browser/ui/app_list/search/history_data_store.h"
12 #include "content/public/browser/browser_context.h"
13 #include "ui/app_list/search/tokenized_string.h" 11 #include "ui/app_list/search/tokenized_string.h"
14 12
15 namespace app_list { 13 namespace app_list {
16 14
17 namespace { 15 namespace {
18 16
19 // Normalize the given string by joining all its tokens with a space. 17 // Normalize the given string by joining all its tokens with a space.
20 std::string NormalizeString(const std::string& utf8) { 18 std::string NormalizeString(const std::string& utf8) {
21 TokenizedString tokenized(base::UTF8ToUTF16(utf8)); 19 TokenizedString tokenized(base::UTF8ToUTF16(utf8));
22 return base::UTF16ToUTF8(JoinString(tokenized.tokens(), ' ')); 20 return base::UTF16ToUTF8(JoinString(tokenized.tokens(), ' '));
23 } 21 }
24 22
25 } // namespace 23 } // namespace
26 24
27 History::History(content::BrowserContext* context) 25 History::History(scoped_refptr<HistoryDataStore> store)
28 : browser_context_(context), 26 : store_(store),
29 data_loaded_(false) { 27 data_loaded_(false) {
30 const char kStoreDataFileName[] = "App Launcher Search";
31 const size_t kMaxQueryEntries = 1000; 28 const size_t kMaxQueryEntries = 1000;
32 const size_t kMaxSecondaryQueries = 5; 29 const size_t kMaxSecondaryQueries = 5;
33 30
34 const base::FilePath data_file =
35 browser_context_->GetPath().AppendASCII(kStoreDataFileName);
36 store_ = new HistoryDataStore(data_file);
37 data_.reset( 31 data_.reset(
38 new HistoryData(store_.get(), kMaxQueryEntries, kMaxSecondaryQueries)); 32 new HistoryData(store_.get(), kMaxQueryEntries, kMaxSecondaryQueries));
39 data_->AddObserver(this); 33 data_->AddObserver(this);
40 } 34 }
41 35
42 History::~History() { 36 History::~History() {
43 data_->RemoveObserver(this); 37 data_->RemoveObserver(this);
44 } 38 }
45 39
46 bool History::IsReady() const { 40 bool History::IsReady() const {
(...skipping 10 matching lines...) Expand all
57 const std::string& query) const { 51 const std::string& query) const {
58 DCHECK(IsReady()); 52 DCHECK(IsReady());
59 return data_->GetKnownResults(NormalizeString(query)).Pass(); 53 return data_->GetKnownResults(NormalizeString(query)).Pass();
60 } 54 }
61 55
62 void History::OnHistoryDataLoadedFromStore() { 56 void History::OnHistoryDataLoadedFromStore() {
63 data_loaded_ = true; 57 data_loaded_ = true;
64 } 58 }
65 59
66 } // namespace app_list 60 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/history.h ('k') | chrome/browser/ui/app_list/search/history_data_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698