Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/app_list/search/history.h" | |
| 6 | |
| 7 #include "base/files/file_path.h" | |
| 8 #include "base/string_util.h" | |
| 9 #include "base/utf_string_conversions.h" | |
| 10 #include "chrome/browser/ui/app_list/search/history_data.h" | |
| 11 #include "chrome/browser/ui/app_list/search/history_data_store.h" | |
| 12 #include "chrome/browser/ui/app_list/search/tokenized_string.h" | |
| 13 #include "content/public/browser/browser_context.h" | |
| 14 | |
| 15 namespace app_list { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // Normalize the given string by joining all its tokens with a space. | |
| 20 std::string NormalizeString(const std::string& utf8) { | |
| 21 TokenizedString tokenized(UTF8ToUTF16(utf8)); | |
| 22 return UTF16ToUTF8(JoinString(tokenized.tokens(), ' ')); | |
| 23 } | |
| 24 | |
| 25 } // namespace | |
| 26 | |
| 27 History::History(content::BrowserContext* context) | |
| 28 : browser_context_(context), | |
| 29 data_loaded_(false) { | |
| 30 const char kStoreDataFileName[] = "App Launcher Search"; | |
|
James Cook
2013/05/23 21:51:08
nit: Consider giving the file an extension, like .
xiyuan
2013/05/23 22:38:13
I did not add an extension because all files under
James Cook
2013/05/24 03:57:05
Consistency is more important than having an exten
| |
| 31 const size_t kMaxQueryEntries = 1000; | |
| 32 const size_t kMaxSecondaryQueries = 5; | |
| 33 | |
| 34 const base::FilePath data_file = | |
| 35 browser_context_->GetPath().AppendASCII(kStoreDataFileName); | |
| 36 store_ = new HistoryDataStore(data_file); | |
| 37 data_.reset(new HistoryData(store_, kMaxQueryEntries, kMaxSecondaryQueries)); | |
| 38 data_->AddObserver(this); | |
| 39 } | |
| 40 | |
| 41 History::~History() { | |
| 42 data_->RemoveObserver(this); | |
| 43 } | |
| 44 | |
| 45 bool History::IsReady() const { | |
| 46 return data_loaded_; | |
| 47 } | |
| 48 | |
| 49 void History::AddLaunchEvent(const std::string& query, | |
| 50 const std::string& result_id) { | |
| 51 DCHECK(IsReady()); | |
| 52 data_->Add(NormalizeString(query), result_id); | |
| 53 } | |
| 54 | |
| 55 scoped_ptr<KnownResults> History::GetKnownResults( | |
| 56 const std::string& query) const { | |
| 57 DCHECK(IsReady()); | |
| 58 return data_->GetKnownResults(NormalizeString(query)).Pass(); | |
| 59 } | |
| 60 | |
| 61 void History::OnHistoryDataLoadedFromStore() { | |
| 62 data_loaded_ = true; | |
| 63 } | |
| 64 | |
| 65 } // namespace app_list | |
| OLD | NEW |