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.content.browser.TracingControllerAndroid;
14 * Basic application functionality that should be shared among all browser applications
15 * based on the content layer.
17 public class ContentApplication extends BaseChromiumApplication {
18 private TracingControllerAndroid mTracingController;
20 TracingControllerAndroid getTracingController() {
21 if (mTracingController == null) {
22 mTracingController = new TracingControllerAndroid(this);
24 return mTracingController;
28 public void onCreate() {
31 // Delay TracingControllerAndroid.registerReceiver() until the main loop is idle.
32 Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() {
34 public boolean queueIdle() {
35 // Will retry if the native library has not been initialized.
36 if (!LibraryLoader.isInitialized()) return true;
39 getTracingController().registerReceiver(ContentApplication.this);
40 } catch (SecurityException e) {
41 // Happens if the process is isolated. Ignore.
43 // Remove the idle handler.
50 * For emulated process environment only. On a production device, the application process is
51 * simply killed without calling this method. We don't need to unregister the broadcast
52 * receiver in the latter case.
55 public void onTerminate() {
57 getTracingController().unregisterReceiver(this);
58 } catch (SecurityException e) {
59 // Happens if the process is isolated. Ignore.