apimall / chromiumembedded

Automatically exported from code.google.com/p/chromiumembedded
0 stars 1 forks source link

Refactor cefclient sample application #1500

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The cefclient sample application has evolved incrementally and haphazardly 
since the CEF project was first started. It's now time to refactor cefclient so 
that it better reflects good application design principles. This includes:

File/code organization:

- Make file extensions consistent with other CEF targets (use .cc instead of 
.cpp).
- Use namespaces to wrap cefclient classes/functions (all cefclient sources in 
'client' namespace, specific tests in `<testname>_test' nested namespace).

General design principles:

- Classes should have well-defined lifespans and access patterns. For example, 
helper classes should be scoped to the parent class' lifespan and only accessed 
on a single thread where possible.
- Use delegates and observers to limit explicit dependencies on other class 
types.
-- Delegates are generally passed to the class constructor and guaranteed to 
outlive the class instance.
-- Multiple observers might be registered on the same class instance and should 
unregister themselves before destruction.
-- Document the thread on which delegate/observer methods will be called.
- Use smart pointer types (scoped_ptr<T>, scoped_refptr<T>, WeakPtr<T>) instead 
of T* where possible.
- When using T* (with delegates, for example) add comments and assertions to 
document/check expected lifespan.
- Use protected/private destructors where possible to compile-time check that 
instances are only deleted via the associated smart pointer types.
- Use DISALLOW_COPY_AND_ASSIGN and similar macros as appropriate.
- Access class members on a single thread and use posted tasks instead of 
locking to protect access where possible.
-- Class methods can internally post to the correct thread when setting members.
-- Use asynchronous callbacks for accessing members that may live on a 
different thread.

Application structure:

- Use a singleton global context class whose lifespan is scoped to main() 
instead of multiple global functions/variables for managing shared state (list 
of existing windows, common file paths, etc).
- Use an abstraction for message loop functionality (Run/Quit/PostTask) instead 
of implementing the same logic multiple times in platform-specific files 
(CefRunMessageLoop vs CefDoMessageLoopWork vs multi-threaded message loop on 
Windows).

Window creation/management:

- Create a class structure to represent different types of native windows and 
browser windows (windowed vs off-screen) with specialized CefClient 
hierarchy/sub-classes.
- Create a root window class representing a native window with title bar and 
resize browser.
-- Optionally show/hide controls (url bar and back/forward/stop/reload buttons).
-- Optionally create as a top-level window or popup window.
-- Optionally create with a windowed browser (created/managed by CEF) or 
off-screen browser (native window with GL context + CefRenderHandler).
-- Create/manage root windows via the singleton global context class.
- Window class implementations will likely be platform-specific (WinAPI vs 
Cocoa vs GTK/X11) while CefClient implementations will likely be shared across 
platforms.

Original issue reported on code.google.com by magreenb...@gmail.com on 22 Jan 2015 at 12:57

GoogleCodeExporter commented 9 years ago
File extensions changed from .cpp to .cc in trunk revision 1981.

Original comment by magreenb...@gmail.com on 22 Jan 2015 at 1:57

GoogleCodeExporter commented 9 years ago
An abstraction for message loop functionality has been added in trunk revision 
1982.

Original comment by magreenb...@gmail.com on 22 Jan 2015 at 5:56

GoogleCodeExporter commented 9 years ago
On Mac we should also remove the helper target build dependencies on code that 
does not actually run in that process (*_test, client_handler, etc).

Original comment by magreenb...@gmail.com on 22 Jan 2015 at 7:54

GoogleCodeExporter commented 9 years ago
Add test_runner as the single entry point for running test-related code and 
move test implementations to the client namespace in trunk revision 1983.

Original comment by magreenb...@gmail.com on 22 Jan 2015 at 8:21

GoogleCodeExporter commented 9 years ago
Use test_runner::Alert instead of platform-specific notifications in trunk 
revision 1984.

Original comment by magreenb...@gmail.com on 22 Jan 2015 at 9:40

GoogleCodeExporter commented 9 years ago
Replace global App* functions with singleton MainContext instance in trunk 
revision 1985.

Original comment by magreenb...@gmail.com on 22 Jan 2015 at 11:11

GoogleCodeExporter commented 9 years ago
Don't specify `virtual` in combination with `OVERRIDE` since it's redundant in 
trunk revision 1986 and revision 1987.

Original comment by magreenb...@gmail.com on 23 Jan 2015 at 4:21

GoogleCodeExporter commented 9 years ago
All files moved to the `client` namespace in trunk revision 1988 and revision 
1989.

Original comment by magreenb...@gmail.com on 23 Jan 2015 at 7:12

GoogleCodeExporter commented 9 years ago
Additional `client` namespace changes in trunk revision 1990. Move Linux GTK 
dialog handlers from ClientHandler into a separate class in trunk revision 1991.

Original comment by magreenb...@gmail.com on 23 Jan 2015 at 8:07

GoogleCodeExporter commented 9 years ago
Trunk revision 1999:
- Split ClientHandler into an abstract base class and a concrete implementation 
for shared usage.
- Show an alert box when selecting Tests > Popup Window while running in 
off-screen rendering mode.
- Mac: Enable/disable UX buttons to match loading state.

Trunk revision 2001:
- Windows: Introduce RootWindow concept and associated window/client object 
hierarchy.
- Remove locking from ClientHandlerShared that was only required for the 
Windows implementation.
- Add CefDeleteOnThread helper for deleting ref-counted types on a named CEF 
thread.

Original comment by magreenb...@gmail.com on 27 Jan 2015 at 12:05

GoogleCodeExporter commented 9 years ago
Trunk revision 2004:
- Introduce RootWindow concept and associated window/client object hierarchy on 
Linux.

Trunk revision 2006:
- Introduce RootWindow concept and associated window/client object hierarchy on 
Mac.

Trunk revision 2008:
- Remove ClientHandler abstraction that is no longer necessary now that all 
platforms use RootWindow

Trunk revision 2009:
- Simplify TempWindow usage.

Original comment by magreenb...@gmail.com on 30 Jan 2015 at 7:11

GoogleCodeExporter commented 9 years ago
Trunk revision 2010, revision 2011, revision 2012, revision 2013 and revision 
2014:
- Restructure files into browser/, common/, renderer/ and resources/ 
directories.
- Mac: Reduce helper process file dependencies.

Trunk revision 2015:
- Split ClientApp into process-specific types.

Original comment by magreenb...@gmail.com on 31 Jan 2015 at 4:49

GoogleCodeExporter commented 9 years ago
Trunk revision 2017:
- Restructure file lists in CMakeLists.txt.in to generate nicer output.

Trunk revision 2018:
- Move files containing the main() program entry point to the top-level 
cefclient directory.

Original comment by magreenb...@gmail.com on 2 Feb 2015 at 10:36