Home | History | Annotate | Download | only in options
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_FONTS_LIST_LOADER_H_
      6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_FONTS_LIST_LOADER_H_
      7 #pragma once
      8 
      9 #include "base/memory/ref_counted.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "base/values.h"
     12 
     13 // This class allows asynchronous retrieval of the system fonts list. The
     14 // loading of the fonts is handled by a platform specific implementation, but
     15 // the retrieval is done on the File thread so that UI does not block for what
     16 // could be a long operation (if the user has a large number of fonts.)
     17 class FontSettingsFontsListLoader
     18     : public base::RefCountedThreadSafe<FontSettingsFontsListLoader> {
     19  public:
     20   // Any clients of this class must implement this observer interface in
     21   // order to be called back when the fonts list has been loaded.
     22   class Observer {
     23    public:
     24     virtual void FontsListHasLoaded() = 0;
     25 
     26    protected:
     27     virtual ~Observer() {}
     28   };
     29 
     30   // Pass in an observer, often 'this'.
     31   explicit FontSettingsFontsListLoader(Observer* observer);
     32 
     33   // Get the font list. This must only be called after receiveing the
     34   // FontsListHasLoaded() notification.
     35   ListValue* GetFontsList();
     36 
     37   // Start loading of the fonts list. The observer will be notified when this
     38   // operation has completed.
     39   void StartLoadFontsList();
     40 
     41   // Set the observer. This class does not take ownership of the observer.
     42   // The observer can be NULL.
     43   void SetObserver(Observer* observer);
     44 
     45  private:
     46   friend class base::RefCountedThreadSafe<FontSettingsFontsListLoader>;
     47 
     48   ~FontSettingsFontsListLoader();
     49 
     50   void GetFontsListOnFileThread();
     51   void FinishFontsListOnUIThread();
     52 
     53   scoped_ptr<ListValue> fonts_list_;
     54   Observer* observer_;  // weak
     55 
     56   DISALLOW_COPY_AND_ASSIGN(FontSettingsFontsListLoader);
     57 };
     58 
     59 #endif  // CHROME_BROWSER_UI_WEBUI_OPTIONS_FONT_SETTINGS_FONTS_LIST_LOADER_H_
     60 
     61