Home | History | Annotate | Download | only in android
      1 // Copyright (c) 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 #ifndef CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_MANAGED_BOOKMARKS_SHIM_H_
      6 #define CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_MANAGED_BOOKMARKS_SHIM_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/observer_list.h"
     11 #include "base/prefs/pref_change_registrar.h"
     12 
     13 class BookmarkNode;
     14 class PrefService;
     15 
     16 // A shim that lives on top of a BookmarkModel that allows the injection of
     17 // policy managed bookmarks without submitting changes to the user configured
     18 // bookmark model.
     19 // Policy managed bookmarks live on a subfolder of the Mobile bookmarks called
     20 // "Managed bookmarks" that isn't editable by the user.
     21 class ManagedBookmarksShim {
     22  public:
     23   class Observer {
     24    public:
     25     virtual ~Observer() {}
     26     virtual void OnManagedBookmarksChanged() = 0;
     27   };
     28 
     29   // Will read managed bookmarks from the given PrefService. The preference
     30   // that contains the bookmarks is managed by policy, and is updated when the
     31   // policy changes.
     32   explicit ManagedBookmarksShim(PrefService* prefs);
     33   ~ManagedBookmarksShim();
     34 
     35   void AddObserver(Observer* observer);
     36   void RemoveObserver(Observer* observer);
     37 
     38   // Returns true if there exists at least one managed bookmark.
     39   bool HasManagedBookmarks() const;
     40   bool IsManagedBookmark(const BookmarkNode* node) const;
     41   const BookmarkNode* GetManagedBookmarksRoot() const;
     42   const BookmarkNode* GetNodeByID(int64 id) const;
     43   const BookmarkNode* GetParentOf(const BookmarkNode* node) const;
     44 
     45  private:
     46   void Reload();
     47 
     48   PrefService* prefs_;
     49   PrefChangeRegistrar registrar_;
     50   scoped_ptr<BookmarkNode> root_;
     51   ObserverList<Observer> observers_;
     52 
     53   DISALLOW_COPY_AND_ASSIGN(ManagedBookmarksShim);
     54 };
     55 
     56 #endif  // CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_MANAGED_BOOKMARKS_SHIM_H_
     57