OLD | NEW |
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 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 if (file_name.length() < kIDStringLength) | 104 if (file_name.length() < kIDStringLength) |
105 return 0; | 105 return 0; |
106 const FilePath::StringType suffix( | 106 const FilePath::StringType suffix( |
107 &file_name[file_name.length() - kIDStringLength]); | 107 &file_name[file_name.length() - kIDStringLength]); |
108 | 108 |
109 if (suffix.length() != kIDStringLength || | 109 if (suffix.length() != kIDStringLength || |
110 suffix[4] != FILE_PATH_LITERAL('-')) { | 110 suffix[4] != FILE_PATH_LITERAL('-')) { |
111 return 0; | 111 return 0; |
112 } | 112 } |
113 | 113 |
| 114 // TODO: Once StringPiece supports a templated interface over the |
| 115 // underlying string type, use it here instead of substr, since that |
| 116 // will avoid needless string copies. StringPiece cannot be used |
| 117 // right now because FilePath::StringType could use either 8 or 16 bit |
| 118 // characters, depending on the OS. |
114 int year, month; | 119 int year, month; |
115 base::StringToInt(suffix.begin(), suffix.begin() + 4, &year); | 120 base::StringToInt(suffix.substr(0, 4), &year); |
116 base::StringToInt(suffix.begin() + 5, suffix.begin() + 7, &month); | 121 base::StringToInt(suffix.substr(5, 2), &month); |
117 | 122 |
118 return year * 100 + month; | 123 return year * 100 + month; |
119 } | 124 } |
120 | 125 |
121 bool TextDatabase::Init() { | 126 bool TextDatabase::Init() { |
122 // Make sure, if we're not allowed to create the file, that it exists. | 127 // Make sure, if we're not allowed to create the file, that it exists. |
123 if (!allow_create_) { | 128 if (!allow_create_) { |
124 if (!file_util::PathExists(file_name_)) | 129 if (!file_util::PathExists(file_name_)) |
125 return false; | 130 return false; |
126 } | 131 } |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } else { | 380 } else { |
376 // Since we got the results in order, we know the last item is the last | 381 // Since we got the results in order, we know the last item is the last |
377 // time we considered. | 382 // time we considered. |
378 *first_time_searched = results->back().time; | 383 *first_time_searched = results->back().time; |
379 } | 384 } |
380 | 385 |
381 statement.Reset(); | 386 statement.Reset(); |
382 } | 387 } |
383 | 388 |
384 } // namespace history | 389 } // namespace history |
OLD | NEW |