| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_ | 5 #ifndef CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_ |
| 6 #define CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_ | 6 #define CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 12 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 | 16 |
| 16 class BookmarkModel; | 17 class BookmarkModel; |
| 17 class BookmarkNode; | 18 class BookmarkNode; |
| 18 | 19 |
| 19 // Helper class that performs operations on a bookmark model and echoes the | 20 // Helper class that performs operations on a bookmark model and echoes the |
| 20 // changes in a verifier model that can be used as an expected hierarchy to | 21 // changes in a verifier model that can be used as an expected hierarchy to |
| 21 // compare against. | 22 // compare against. |
| 22 // Note: When we refer to the "same" node in |model| and |verifier_model_|, | 23 // Note: When we refer to the "same" node in |model| and |verifier_model_|, |
| 23 // we mean the same canonical bookmark entity, because |verifier_model_| is | 24 // we mean the same canonical bookmark entity, because |verifier_model_| is |
| 24 // expected to be a replica of |model|. | 25 // expected to be a replica of |model|. |
| 25 class BookmarkModelVerifier { | 26 class BookmarkModelVerifier { |
| 26 public: | 27 public: |
| 27 explicit BookmarkModelVerifier(BookmarkModel* model) | 28 explicit BookmarkModelVerifier(BookmarkModel* model) |
| 28 : verifier_model_(model), | 29 : verifier_model_(model), |
| 29 use_verifier_model_(true) {} | 30 use_verifier_model_(true) {} |
| 30 | 31 |
| 31 ~BookmarkModelVerifier() {} | 32 ~BookmarkModelVerifier() {} |
| 32 | 33 |
| 33 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in | 34 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in |
| 34 // terms of the data model. Compares favicons if |compare_favicons| is true. | 35 // terms of the data model and favicon. Returns true if they both match. |
| 35 // Returns true if they match. | |
| 36 // Note: Some peripheral fields like creation times are allowed to mismatch. | 36 // Note: Some peripheral fields like creation times are allowed to mismatch. |
| 37 static bool ModelsMatch(BookmarkModel* model_a, | 37 static bool ModelsMatch(BookmarkModel* model_a, |
| 38 BookmarkModel* model_b, | 38 BookmarkModel* model_b) WARN_UNUSED_RESULT; |
| 39 bool compare_favicons) WARN_UNUSED_RESULT; | |
| 40 | |
| 41 // Same as the above method, but does not check if the favicons match. | |
| 42 static bool ModelsMatch(BookmarkModel* model_a, | |
| 43 BookmarkModel* model_b) WARN_UNUSED_RESULT { | |
| 44 return ModelsMatch(model_a, model_b, false); | |
| 45 } | |
| 46 | 39 |
| 47 // Checks if |model| contains any instances of two bookmarks with the same URL | 40 // Checks if |model| contains any instances of two bookmarks with the same URL |
| 48 // under the same parent folder. Returns true if even one instance is found. | 41 // under the same parent folder. Returns true if even one instance is found. |
| 49 static bool ContainsDuplicateBookmarks(BookmarkModel* model); | 42 static bool ContainsDuplicateBookmarks(BookmarkModel* model); |
| 50 | 43 |
| 51 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent. | 44 // Checks if the favicon data in |bitmap_a| and |bitmap_b| are equivalent. |
| 52 // Returns true if they match. | 45 // Returns true if they match. |
| 53 static bool FaviconsMatch(const SkBitmap& bitmap_a, const SkBitmap& bitmap_b); | 46 static bool FaviconsMatch(const SkBitmap& bitmap_a, const SkBitmap& bitmap_b); |
| 54 | 47 |
| 55 // Adds the same bookmark to |model| and |verifier_model_|. See | 48 // Adds the same bookmark to |model| and |verifier_model_|. See |
| (...skipping 10 matching lines...) Expand all Loading... |
| 66 const BookmarkNode* parent, | 59 const BookmarkNode* parent, |
| 67 int index, | 60 int index, |
| 68 const string16& title); | 61 const string16& title); |
| 69 | 62 |
| 70 // Sets the title of the same node in |model| and |verifier_model_|. See | 63 // Sets the title of the same node in |model| and |verifier_model_|. See |
| 71 // BookmarkModel::SetTitle for details. | 64 // BookmarkModel::SetTitle for details. |
| 72 void SetTitle(BookmarkModel* model, | 65 void SetTitle(BookmarkModel* model, |
| 73 const BookmarkNode* node, | 66 const BookmarkNode* node, |
| 74 const string16& title); | 67 const string16& title); |
| 75 | 68 |
| 69 // Sets the favicon of the same node in |model| and |verifier_model_| using |
| 70 // the data in |icon_bytes_vector|. |
| 71 // See BookmarkChangeProcessor::ApplyBookmarkFavicon for details. |
| 72 void SetFavicon(BookmarkModel* model, |
| 73 const BookmarkNode* node, |
| 74 const std::vector<unsigned char>& icon_bytes_vector); |
| 75 |
| 76 // Moves the same node to the same position in both |model| and | 76 // Moves the same node to the same position in both |model| and |
| 77 // |verifier_model_|. See BookmarkModel::Move for details. | 77 // |verifier_model_|. See BookmarkModel::Move for details. |
| 78 void Move(BookmarkModel* model, | 78 void Move(BookmarkModel* model, |
| 79 const BookmarkNode* node, | 79 const BookmarkNode* node, |
| 80 const BookmarkNode* new_parent, | 80 const BookmarkNode* new_parent, |
| 81 int index); | 81 int index); |
| 82 | 82 |
| 83 // Removes the same node from |model| and |verifier_model_|. See | 83 // Removes the same node from |model| and |verifier_model_|. See |
| 84 // BookmarkModel::Remove for details. | 84 // BookmarkModel::Remove for details. |
| 85 void Remove(BookmarkModel* model, const BookmarkNode* parent, int index); | 85 void Remove(BookmarkModel* model, const BookmarkNode* parent, int index); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 BookmarkModel* verifier_model_; | 118 BookmarkModel* verifier_model_; |
| 119 | 119 |
| 120 // A flag that indicates whether bookmark operations should also update the | 120 // A flag that indicates whether bookmark operations should also update the |
| 121 // verifier model or not. | 121 // verifier model or not. |
| 122 bool use_verifier_model_; | 122 bool use_verifier_model_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(BookmarkModelVerifier); | 124 DISALLOW_COPY_AND_ASSIGN(BookmarkModelVerifier); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 #endif // CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_ | 127 #endif // CHROME_TEST_LIVE_SYNC_BOOKMARK_MODEL_VERIFIER_H_ |
| OLD | NEW |