1 // Copyright 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.
5 package org.chromium.content.app;
7 import android.os.Looper;
8 import android.os.MessageQueue;
10 import org.chromium.base.BaseChromiumApplication;
11 import org.chromium.base.library_loader.LibraryLoader;
12 import org.chromium.content.browser.TracingControllerAndroid;
15 * Basic application functionality that should be shared among all browser applications
16 * based on the content layer.
18 public class ContentApplication extends BaseChromiumApplication {
19 private TracingControllerAndroid mTracingController;
21 TracingControllerAndroid getTracingController() {
22 if (mTracingController == null) {
23 mTracingController = new TracingControllerAndroid(this);
25 return mTracingController;
29 public void onCreate() {
32 // Delay TracingControllerAndroid.registerReceiver() until the main loop is idle.
33 Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
35 public boolean queueIdle() {
36 // Will retry if the native library has not been initialized.
37 if (!LibraryLoader.isInitialized()) return true;
40 getTracingController().registerReceiver(ContentApplication.this);
41 } catch (SecurityException e) {
42 // Happens if the process is isolated. Ignore.
44 // Remove the idle handler.
51 * For emulated process environment only. On a production device, the application process is
52 * simply killed without calling this method. We don't need to unregister the broadcast
53 * receiver in the latter case.
56 public void onTerminate() {
58 getTracingController().unregisterReceiver(this);
59 } catch (SecurityException e) {
60 // Happens if the process is isolated. Ignore.