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

Side by Side Diff: chrome/browser/history/text_database.cc

Issue 8921006: Standardize StringToInt{,64} interface. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix namespace issues. Created 9 years 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <limits> 5 #include <limits>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include "chrome/browser/history/text_database.h" 9 #include "chrome/browser/history/text_database.h"
10 10
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_piece.h"
erikwright (departed) 2011/12/14 19:09:58 I guess we don't need this include at the moment.
15 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
16 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" 18 #include "chrome/browser/diagnostics/sqlite_diagnostics.h"
18 #include "sql/statement.h" 19 #include "sql/statement.h"
19 #include "sql/transaction.h" 20 #include "sql/transaction.h"
20 21
21 // There are two tables in each database, one full-text search (FTS) table which 22 // There are two tables in each database, one full-text search (FTS) table which
22 // indexes the contents and title of the pages. The other is a regular SQLITE 23 // indexes the contents and title of the pages. The other is a regular SQLITE
23 // table which contains non-indexed information about the page. All columns of 24 // table which contains non-indexed information about the page. All columns of
24 // a FTS table are indexed using the text search algorithm, which isn't what we 25 // a FTS table are indexed using the text search algorithm, which isn't what we
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 if (file_name.length() < kIDStringLength) 105 if (file_name.length() < kIDStringLength)
105 return 0; 106 return 0;
106 const FilePath::StringType suffix( 107 const FilePath::StringType suffix(
107 &file_name[file_name.length() - kIDStringLength]); 108 &file_name[file_name.length() - kIDStringLength]);
108 109
109 if (suffix.length() != kIDStringLength || 110 if (suffix.length() != kIDStringLength ||
110 suffix[4] != FILE_PATH_LITERAL('-')) { 111 suffix[4] != FILE_PATH_LITERAL('-')) {
111 return 0; 112 return 0;
112 } 113 }
113 114
115 // TODO: Once StringPiece supports a templated interface over the
116 // underlying string type, use it here instead of substr, since that
117 // will avoid needless string copies. StringPiece cannot be used
118 // right now because FilePath::StringType could use either 8 or 16 bit
119 // characters, depending on the OS.
114 int year, month; 120 int year, month;
115 base::StringToInt(suffix.begin(), suffix.begin() + 4, &year); 121 base::StringToInt(suffix.substr(0, 4), &year);
116 base::StringToInt(suffix.begin() + 5, suffix.begin() + 7, &month); 122 base::StringToInt(suffix.substr(5, 2), &month);
117 123
118 return year * 100 + month; 124 return year * 100 + month;
119 } 125 }
120 126
121 bool TextDatabase::Init() { 127 bool TextDatabase::Init() {
122 // Make sure, if we're not allowed to create the file, that it exists. 128 // Make sure, if we're not allowed to create the file, that it exists.
123 if (!allow_create_) { 129 if (!allow_create_) {
124 if (!file_util::PathExists(file_name_)) 130 if (!file_util::PathExists(file_name_))
125 return false; 131 return false;
126 } 132 }
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } else { 381 } else {
376 // Since we got the results in order, we know the last item is the last 382 // Since we got the results in order, we know the last item is the last
377 // time we considered. 383 // time we considered.
378 *first_time_searched = results->back().time; 384 *first_time_searched = results->back().time;
379 } 385 }
380 386
381 statement.Reset(); 387 statement.Reset();
382 } 388 }
383 389
384 } // namespace history 390 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698